BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
22724418
Commit
22724418
authored
Jul 10, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add User#disable_two_factor!
This method encapsulates all the logic for disabling 2FA on a specific User model.
parent
52681358
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
17 deletions
+33
-17
two_factor_auths_controller.rb
app/controllers/profiles/two_factor_auths_controller.rb
+1
-7
user.rb
app/models/user.rb
+10
-0
two_factor_auths_controller_spec.rb
.../controllers/profiles/two_factor_auths_controller_spec.rb
+3
-10
factories.rb
spec/factories.rb
+1
-0
user_spec.rb
spec/models/user_spec.rb
+18
-0
No files found.
app/controllers/profiles/two_factor_auths_controller.rb
View file @
22724418
...
...
@@ -29,13 +29,7 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
end
def
destroy
current_user
.
update_attributes
({
two_factor_enabled:
false
,
encrypted_otp_secret:
nil
,
encrypted_otp_secret_iv:
nil
,
encrypted_otp_secret_salt:
nil
,
otp_backup_codes:
nil
})
current_user
.
disable_two_factor!
redirect_to
profile_account_path
end
...
...
app/models/user.rb
View file @
22724418
...
...
@@ -322,6 +322,16 @@ class User < ActiveRecord::Base
@reset_token
end
def
disable_two_factor!
update_attributes
(
two_factor_enabled:
false
,
encrypted_otp_secret:
nil
,
encrypted_otp_secret_iv:
nil
,
encrypted_otp_secret_salt:
nil
,
otp_backup_codes:
nil
)
end
def
namespace_uniq
namespace_name
=
self
.
username
existing_namespace
=
Namespace
.
by_path
(
namespace_name
)
...
...
spec/controllers/profiles/two_factor_auths_controller_spec.rb
View file @
22724418
...
...
@@ -105,19 +105,12 @@ describe Profiles::TwoFactorAuthsController do
end
describe
'DELETE destroy'
do
let
(
:user
)
{
create
(
:user
,
:two_factor
)
}
let!
(
:codes
)
{
user
.
generate_otp_backup_codes!
}
let
(
:user
)
{
create
(
:user
,
:two_factor
)
}
it
'clears all 2FA-related fields'
do
expect
(
user
).
to
be_two_factor_enabled
expect
(
user
.
otp_backup_codes
).
not_to
be_nil
expect
(
user
.
encrypted_otp_secret
).
not_to
be_nil
it
'disables two factor'
do
expect
(
user
).
to
receive
(
:disable_two_factor!
)
delete
:destroy
expect
(
user
).
not_to
be_two_factor_enabled
expect
(
user
.
otp_backup_codes
).
to
be_nil
expect
(
user
.
encrypted_otp_secret
).
to
be_nil
end
it
'redirects to profile_account_path'
do
...
...
spec/factories.rb
View file @
22724418
...
...
@@ -32,6 +32,7 @@ FactoryGirl.define do
before
(
:create
)
do
|
user
|
user
.
two_factor_enabled
=
true
user
.
otp_secret
=
User
.
generate_otp_secret
(
32
)
user
.
generate_otp_backup_codes!
end
end
...
...
spec/models/user_spec.rb
View file @
22724418
...
...
@@ -217,6 +217,24 @@ describe User do
end
end
describe
'#disable_two_factor!'
do
it
'clears all 2FA-related fields'
do
user
=
create
(
:user
,
:two_factor
)
expect
(
user
).
to
be_two_factor_enabled
expect
(
user
.
encrypted_otp_secret
).
not_to
be_nil
expect
(
user
.
otp_backup_codes
).
not_to
be_nil
user
.
disable_two_factor!
expect
(
user
).
not_to
be_two_factor_enabled
expect
(
user
.
encrypted_otp_secret
).
to
be_nil
expect
(
user
.
encrypted_otp_secret_iv
).
to
be_nil
expect
(
user
.
encrypted_otp_secret_salt
).
to
be_nil
expect
(
user
.
otp_backup_codes
).
to
be_nil
end
end
describe
'projects'
do
before
do
@user
=
create
:user
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment