Skip to content

Commit

Permalink
Don't include Nonce and Created for PasswordText.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Kingdon committed Jan 11, 2011
1 parent 26b4eae commit 4e57b31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
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

0 comments on commit 4e57b31

Please sign in to comment.