Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup param string creation, use .new_access_token

  • Loading branch information...
commit 7c20e1e6bd94119d9f49104a682e58a5b56d3fc5 1 parent 4aa782a
@evanphx authored
View
14 lib/orthrus/ssh/rack_app.rb
@@ -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
@@ -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)
@@ -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
View
2  test/sessions.rb
@@ -21,7 +21,7 @@ def find_session(id)
["secret", @pub]
end
- def access_token
+ def new_access_token(session_id)
1
end
end
View
8 test/test_orthrus_ssh_rackapp.rb
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.