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

Ignore case of the userid when validating it. #396

Merged
merged 3 commits into from
Jun 21, 2018
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
6 changes: 3 additions & 3 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2615,9 +2615,9 @@
- :name: delete
:identifier: dialog_delete
- :name: create
:identifier: dialog_new
:identifier: dialog_new_editor
- :name: edit
:identifier: dialog_edit
:identifier: dialog_edit_editor
- :name: copy
:identifier: dialog_copy_editor
:resource_actions:
Expand All @@ -2632,7 +2632,7 @@
- :name: delete
:identifier: dialog_delete
- :name: edit
:identifier: dialog_edit
:identifier: dialog_edit_editor
- :name: copy
:identifier: dialog_copy_editor
:delete:
Expand Down
2 changes: 1 addition & 1 deletion lib/services/api/user_token_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def log_init(mod, name, options)
end

def validate_userid(userid)
raise "Invalid userid #{userid} specified" unless User.exists?(:userid => userid)
raise "Invalid userid #{userid} specified" unless User.in_my_region.where('lower(userid) = ?', userid.downcase).exists?
end
end
end
20 changes: 13 additions & 7 deletions spec/lib/services/api/user_token_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
RSpec.describe Api::UserTokenService do
describe ".generate_token" do
before do
@user = FactoryGirl.create(:user_with_group)
end
before do
@user = FactoryGirl.create(:user_with_group)
end

let(:user_token_service) { described_class.new }
let(:token) { user_token_service.generate_token(@user.userid.capitalize, 'api', :token_ttl => token_ttl) }
let(:token_info) { user_token_service.token_mgr('api').token_get_info(token) }
let(:user_token_service) { described_class.new }
let(:token) { user_token_service.generate_token(@user.userid.capitalize, 'api', :token_ttl => token_ttl) }
let(:token_info) { user_token_service.token_mgr('api').token_get_info(token) }

describe ".generate_token" do
context "without token_ttl set" do
let(:token_ttl) { nil }

Expand All @@ -24,4 +24,10 @@
end
end
end

describe ".validate_userid" do
it "ignores the case of the userid" do
expect { user_token_service.send(:validate_userid, @user.userid.capitalize) }.not_to raise_error
end
end
end