Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add private label otp enabled for user
- Loading branch information
Yehor Chumak
committed
May 22, 2020
1 parent
6456c74
commit 0400aa7
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
describe 'Api::V2::Resource::Otp' do | ||
include_context 'bearer authentication' | ||
let!(:create_member_permission) do | ||
create :permission, | ||
role: 'member' | ||
end | ||
let(:do_request) { post '/api/v2/resource/otp/enable', headers: auth_header } | ||
let(:otp_code) { '111111' } | ||
|
||
context 'valid request' do | ||
before do | ||
allow(TOTPService).to receive(:validate?) | ||
.with(test_user.uid, otp_code) { true } | ||
end | ||
|
||
it 'user enables 2fa successfully' do | ||
post '/api/v2/resource/otp/enable', headers: auth_header, params: { | ||
code: otp_code | ||
} | ||
|
||
expect(response.status).to eq 201 | ||
expect(test_user.reload.otp).to eq true | ||
expect(test_user.reload.labels.find_by(key: :otp, scope: :private)).not_to eq nil | ||
end | ||
end | ||
|
||
context 'incomplete request' do | ||
it 'user receives error' do | ||
post '/api/v2/resource/otp/enable', headers: auth_header, params: { | ||
code: otp_code | ||
} | ||
|
||
expect(response.status).to eq 422 | ||
expect(test_user.reload.otp).to eq false | ||
expect(test_user.reload.labels.find_by(key: :otp, scope: :private)).to eq nil | ||
end | ||
end | ||
end |