Skip to content

Commit

Permalink
Cleanup param string creation, use .new_access_token
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Mar 27, 2012
1 parent 4aa782a commit 7c20e1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
14 changes: 8 additions & 6 deletions lib/orthrus/ssh/rack_app.rb
Expand Up @@ -25,7 +25,7 @@ def call(env)
def form(body)
[200,
{ "Content-Type" => "application/x-www-form-urlencoded" },
[body]
[Rack::Utils.build_query(body)]
]
end

Expand All @@ -34,14 +34,14 @@ def find(req)
id = req.params["id"]

unless pub = @sessions.find_key(user, id)
return form("code=unknown")
return form :code => "unknown"
end

session, nonce = @sessions.new_session(user, pub)

nonce = Rack::Utils.escape Utils.sha1_hash(nonce)
nonce = Utils.sha1_hash(nonce)

form "code=check&session_id=#{session}&nonce=#{nonce}"
form :code => 'check', :session_id => session, :nonce => nonce
end

def verify(req)
Expand All @@ -52,10 +52,12 @@ def verify(req)

sig = req.params['sig']

token = @sessions.new_access_token(id)

if pub.verify(sig, nonce, true)
form "code=verified&access_token=1"
form :code => 'verified', :access_token => token
else
form "code=fail"
form :code => "fail"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/sessions.rb
Expand Up @@ -21,7 +21,7 @@ def find_session(id)
["secret", @pub]
end

def access_token
def new_access_token(session_id)
1
end
end
Expand Down
8 changes: 6 additions & 2 deletions test/test_orthrus_ssh_rackapp.rb
Expand Up @@ -34,7 +34,8 @@ def test_call_unable_to_find_identity
assert_equal "application/x-www-form-urlencoded",
headers["Content-Type"]

assert_equal "code=unknown", body[0]
params = Rack::Utils.parse_query body[0]
assert_equal "unknown", params['code']
end

def test_call_requests_signature
Expand Down Expand Up @@ -79,6 +80,9 @@ def test_call_verifies_signature

code, headers, body = @app.call(env)

assert_equal ["code=verified&access_token=1"], body
params = Rack::Utils.parse_query body.first

assert_equal "verified", params['code']
assert_equal "1", params["access_token"]
end
end

0 comments on commit 7c20e1e

Please sign in to comment.