Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
7b8bd93e
Commit
7b8bd93e
authored
Sep 04, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite OAuth specs
parent
3832b2aa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
88 deletions
+56
-88
spec/lib/auth_spec.rb
spec/lib/auth_spec.rb
+12
-88
spec/lib/oauth_spec.rb
spec/lib/oauth_spec.rb
+44
-0
No files found.
spec/lib/auth_spec.rb
View file @
7b8bd93e
...
@@ -3,102 +3,26 @@ require 'spec_helper'
...
@@ -3,102 +3,26 @@ require 'spec_helper'
describe
Gitlab
::
Auth
do
describe
Gitlab
::
Auth
do
let
(
:gl_auth
)
{
Gitlab
::
Auth
.
new
}
let
(
:gl_auth
)
{
Gitlab
::
Auth
.
new
}
before
do
describe
:find
do
Gitlab
.
config
.
stub
(
omniauth:
{})
@info
=
mock
(
uid:
'12djsak321'
,
name:
'John'
,
email:
'john@mail.com'
)
end
describe
:find_for_ldap_auth
do
before
do
before
do
@auth
=
mock
(
@user
=
create
(
uid:
'12djsak321'
,
:user
,
info:
@info
,
username:
'john'
,
provider:
'ldap'
password:
'888777'
,
password_confirmation:
'888777'
)
)
end
end
it
"should find by uid & provider"
do
it
"should find user by valid login/password"
do
User
.
should_receive
:find_by_extern_uid_and_provider
gl_auth
.
find
(
'john'
,
'888777'
).
should
==
@user
gl_auth
.
find_for_ldap_auth
(
@auth
)
end
it
"should update credentials by email if missing uid"
do
user
=
double
(
'User'
)
User
.
stub
find_by_extern_uid_and_provider:
nil
User
.
stub
find_by_email:
user
user
.
should_receive
:update_attributes
gl_auth
.
find_for_ldap_auth
(
@auth
)
end
it
"should create from auth if user does not exist"
do
User
.
stub
find_by_extern_uid_and_provider:
nil
User
.
stub
find_by_email:
nil
gl_auth
.
should_receive
:create_from_omniauth
gl_auth
.
find_for_ldap_auth
(
@auth
)
end
end
describe
:find_or_new_for_omniauth
do
before
do
@auth
=
mock
(
info:
@info
,
provider:
'twitter'
,
uid:
'12djsak321'
,
)
end
end
it
"should find user"
do
it
"should not find user with invalid password"
do
User
.
should_receive
:find_by_provider_and_extern_uid
gl_auth
.
find
(
'john'
,
'invalid'
).
should_not
==
@user
gl_auth
.
should_not_receive
:create_from_omniauth
gl_auth
.
find_or_new_for_omniauth
(
@auth
)
end
end
it
"should not create user"
do
it
"should not find user with invalid login and password"
do
User
.
stub
find_by_provider_and_extern_uid:
nil
gl_auth
.
find
(
'jon'
,
'invalid'
).
should_not
==
@user
gl_auth
.
should_not_receive
:create_from_omniauth
gl_auth
.
find_or_new_for_omniauth
(
@auth
)
end
it
"should create user if single_sing_on"
do
Gitlab
.
config
.
omniauth
[
'allow_single_sign_on'
]
=
true
User
.
stub
find_by_provider_and_extern_uid:
nil
gl_auth
.
should_receive
:create_from_omniauth
gl_auth
.
find_or_new_for_omniauth
(
@auth
)
end
end
describe
:create_from_omniauth
do
it
"should create user from LDAP"
do
@auth
=
mock
(
info:
@info
,
provider:
'ldap'
)
user
=
gl_auth
.
create_from_omniauth
(
@auth
,
true
)
user
.
should
be_valid
user
.
extern_uid
.
should
==
@info
.
uid
user
.
provider
.
should
==
'ldap'
end
it
"should create user from Omniauth"
do
@auth
=
mock
(
info:
@info
,
provider:
'twitter'
)
user
=
gl_auth
.
create_from_omniauth
(
@auth
,
false
)
user
.
should
be_valid
user
.
extern_uid
.
should
==
@info
.
uid
user
.
provider
.
should
==
'twitter'
end
it
"should apply defaults to user"
do
@auth
=
mock
(
info:
@info
,
provider:
'ldap'
)
user
=
gl_auth
.
create_from_omniauth
(
@auth
,
true
)
user
.
should
be_valid
user
.
projects_limit
.
should
==
Gitlab
.
config
.
gitlab
.
default_projects_limit
user
.
can_create_group
.
should
==
Gitlab
.
config
.
gitlab
.
default_can_create_group
end
end
end
end
end
end
spec/lib/oauth_spec.rb
0 → 100644
View file @
7b8bd93e
require
'spec_helper'
describe
Gitlab
::
OAuth
::
User
do
let
(
:gl_auth
)
{
Gitlab
::
OAuth
::
User
}
before
do
Gitlab
.
config
.
stub
(
omniauth:
{})
@info
=
mock
(
uid:
'12djsak321'
,
name:
'John'
,
email:
'john@mail.com'
)
end
describe
:create
do
it
"should create user from LDAP"
do
@auth
=
mock
(
info:
@info
,
provider:
'ldap'
)
user
=
gl_auth
.
create
(
@auth
)
user
.
should
be_valid
user
.
extern_uid
.
should
==
@info
.
uid
user
.
provider
.
should
==
'ldap'
end
it
"should create user from Omniauth"
do
@auth
=
mock
(
info:
@info
,
provider:
'twitter'
)
user
=
gl_auth
.
create
(
@auth
)
user
.
should
be_valid
user
.
extern_uid
.
should
==
@info
.
uid
user
.
provider
.
should
==
'twitter'
end
it
"should apply defaults to user"
do
@auth
=
mock
(
info:
@info
,
provider:
'ldap'
)
user
=
gl_auth
.
create
(
@auth
)
user
.
should
be_valid
user
.
projects_limit
.
should
==
Gitlab
.
config
.
gitlab
.
default_projects_limit
user
.
can_create_group
.
should
==
Gitlab
.
config
.
gitlab
.
default_can_create_group
end
end
end
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