Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't include Nonce and Created for PasswordText #131

Merged
1 commit merged into from
Jan 11, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions lib/savon/wsse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,19 @@ def to_xml

# Returns a Hash containing wsse:UsernameToken details.
def wsse_username_token
wsse_security "UsernameToken",
"wsse:Username" => username,
"wsse:Nonce" => nonce,
"wsu:Created" => timestamp,
"wsse:Password" => password_value,
:attributes! => { "wsse:Password" => { "Type" => password_type } }
if digest?
wsse_security "UsernameToken",
"wsse:Username" => username,
"wsse:Nonce" => nonce,
"wsu:Created" => timestamp,
"wsse:Password" => password_value,
:attributes! => { "wsse:Password" => { "Type" => PasswordDigestURI } }
else
wsse_security "UsernameToken",
"wsse:Username" => username,
"wsse:Password" => password,
:attributes! => { "wsse:Password" => { "Type" => PasswordTextURI } }
end
end

# Returns a Hash containing wsse:Timestamp details.
Expand All @@ -107,19 +114,14 @@ def wsse_security(tag, hash)
}
end

# Returns the WSSE password. Encrypts the password for digest authentication.
# Returns the WSSE password, encrypted for digest authentication.
def password_value
return password unless digest?
raise "internal error: digest only" unless digest?

token = nonce + timestamp + password
Base64.encode64(Digest::SHA1.hexdigest(token)).chomp!
end

# Returns the URI for the "wsse:Password/@Type" attribute.
def password_type
digest? ? PasswordDigestURI : PasswordTextURI
end

# Returns a WSSE nonce.
def nonce
@nonce ||= Digest::SHA1.hexdigest random_string + timestamp
Expand Down
8 changes: 4 additions & 4 deletions spec/savon/wsse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@
wsse.to_xml.should include("username", "password")
end

it "should contain a wsse:Nonce tag" do
wsse.to_xml.should match(/<wsse:Nonce>\w+<\/wsse:Nonce>/)
it "should not contain a wsse:Nonce tag" do
wsse.to_xml.should_not match(/<wsse:Nonce>.*<\/wsse:Nonce>/)
end

it "should contain a wsu:Created tag" do
wsse.to_xml.should match(/<wsu:Created>#{Savon::SOAP::DateTimeRegexp}.+<\/wsu:Created>/)
it "should not contain a wsu:Created tag" do
wsse.to_xml.should_not match(/<wsu:Created>.*<\/wsu:Created>/)
end

it "should contain the PasswordText type attribute" do
Expand Down