Commit 3c96d8b79773004868d3a1d2ef8f48de1cce6731
1 parent
f35e081b
Exists in
master
and in
29 other branches
[stoa] Adding support for usp_id authentication on stoa web-service
Showing
2 changed files
with
24 additions
and
1 deletions
Show diff stats
plugins/stoa/controllers/stoa_plugin_controller.rb
... | ... | @@ -3,7 +3,13 @@ class StoaPluginController < PublicController |
3 | 3 | |
4 | 4 | def authenticate |
5 | 5 | if request.ssl? && request.post? |
6 | - user = User.authenticate(params[:login], params[:password], environment) | |
6 | + if params[:login].blank? | |
7 | + person = Person.find_by_usp_id(params[:usp_id]) | |
8 | + login = person ? person.user.login : nil | |
9 | + else | |
10 | + login = params[:login] | |
11 | + end | |
12 | + user = User.authenticate(login, params[:password], environment) | |
7 | 13 | if user |
8 | 14 | result = { |
9 | 15 | :username => user.login, | ... | ... |
plugins/stoa/test/functional/stoa_plugin_controller_test.rb
... | ... | @@ -90,6 +90,23 @@ class StoaPluginControllerTest < ActionController::TestCase |
90 | 90 | assert !json_response['exists'] |
91 | 91 | end |
92 | 92 | |
93 | + should 'authenticate with usp_id' do | |
94 | + @request.stubs(:ssl?).returns(true) | |
95 | + post :authenticate, :usp_id => user.person.usp_id.to_s, :password => '123456' | |
96 | + | |
97 | + assert_nil json_response['error'] | |
98 | + assert_equal user.login, json_response['username'] | |
99 | + end | |
100 | + | |
101 | + should 'not crash if usp_id is invalid' do | |
102 | + @request.stubs(:ssl?).returns(true) | |
103 | + assert_nothing_raised do | |
104 | + post :authenticate, :usp_id => 12321123, :password => '123456' | |
105 | + end | |
106 | + assert_not_nil json_response['error'] | |
107 | + assert_match /user/,json_response['error'] | |
108 | + end | |
109 | + | |
93 | 110 | private |
94 | 111 | |
95 | 112 | def json_response | ... | ... |