Skip to content

Instantly share code, notes, and snippets.

@hannahwhy
Created January 27, 2011 22:15
Show Gist options
  • Save hannahwhy/a19b7f7a622ab7b12396 to your computer and use it in GitHub Desktop.
Save hannahwhy/a19b7f7a622ab7b12396 to your computer and use it in GitHub Desktop.
diff --git a/spec/castanet/responses/ticket_validate_spec.rb b/spec/castanet/responses/ticket_validate_spec.rb
index a75758c..8dad95d 100644
--- a/spec/castanet/responses/ticket_validate_spec.rb
+++ b/spec/castanet/responses/ticket_validate_spec.rb
@@ -1,17 +1,37 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require 'tempfile'
+
module Castanet::Responses
describe TicketValidate do
describe '.from_cas' do
describe 'on success' do
- let(:response) do
- TicketValidate.from_cas(%Q{
- <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
+ let(:response_text) do
+ %Q{<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>username</cas:user>
</cas:authenticationSuccess>
- </cas:serviceResponse>
- })
+ </cas:serviceResponse>}
+ end
+
+ let(:response) do
+ TicketValidate.from_cas(response_text)
+ end
+
+ describe 'given UTF-16' do
+ it 'returns authentication success' do
+ resp = nil
+
+ Tempfile.open('test') do |f|
+ f.write(response_text)
+ f.flush
+
+ new_text = `iconv -f UTF-8 -t UTF-16 #{f.path}`
+ resp = TicketValidate.from_cas(new_text)
+ end
+
+ resp.should be_ok
+ end
end
$ bundle exec ruby spec/castanet/responses/ticket_validate_spec.rb
...F.....
Failures:
1) Castanet::Responses::TicketValidate.from_cas on success given UTF-16 returns authentication success
Failure/Error: resp = TicketValidate.from_cas(new_text)
ArgumentError:
invalid byte sequence in UTF-8
# ./lib/castanet/responses/ticket_validate.rb:92:in `strip'
# ./lib/castanet/responses/ticket_validate.rb:92:in `from_cas'
# spec/castanet/responses/ticket_validate_spec.rb:30:in `block (6 levels) in <module:Responses>'
# spec/castanet/responses/ticket_validate_spec.rb:25:in `block (5 levels) in <module:Responses>'
@hannahwhy
Copy link
Author

One thing I didn't check, and just checked now: the returned string from the iconv invocation is actually tagged as being in UTF-8, not UTF-16. Unfortunately, I'm not having any luck getting Ruby 1.9.2-p136 to either do the UTF-8 -> UTF-16 transcode itself, or force UTF-16 encoding in the result: in both cases I'm met with unknown encoding name - UTF-16. Specifying UTF16 as the encoding name also doesn't work, nor does the more explicit UTF16_LE. Didn't try big-endian UTF-16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment