Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2017-01-02 14:56:58 +0000
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
f2917fc462c2ce616905af10c75088a1b4fadc5d
f2917fc4
1 parent
7c8c4c2a
Added tests to cover social login actions
Closes #244
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
3 deletions
app/Services/SocialAuthService.php
resources/views/auth/login.blade.php
tests/Auth/SocialAuthTest.php
app/Services/SocialAuthService.php
View file @
f2917fc
...
...
@@ -98,7 +98,6 @@ class SocialAuthService
// Get any attached social accounts or users
$socialAccount
=
$this
->
socialAccount
->
where
(
'driver_id'
,
'='
,
$socialId
)
->
first
();
$user
=
$this
->
userRepo
->
getByEmail
(
$socialUser
->
getEmail
());
$isLoggedIn
=
auth
()
->
check
();
$currentUser
=
user
();
...
...
resources/views/auth/login.blade.php
View file @
f2917fc
...
...
@@ -34,10 +34,10 @@
<hr
class=
"margin-top"
>
<h3
class=
"text-muted"
>
{{ trans('auth.social_login') }}
</h3>
@if(isset($socialDrivers['google']))
<a
href=
"{{ baseUrl("
/
login
/
service
/
google
")
}}"
style=
"color: #DC4E41;"
><i
class=
"zmdi zmdi-google-plus-box zmdi-hc-4x"
></i></a>
<a
id=
"social-login-google"
href=
"{{ baseUrl("
/
login
/
service
/
google
")
}}"
style=
"color: #DC4E41;"
><i
class=
"zmdi zmdi-google-plus-box zmdi-hc-4x"
></i></a>
@endif
@if(isset($socialDrivers['github']))
<a
href=
"{{ baseUrl("
/
login
/
service
/
github
")
}}"
style=
"color:#444;"
><i
class=
"zmdi zmdi-github zmdi-hc-4x"
></i></a>
<a
id=
"social-login-github"
href=
"{{ baseUrl("
/
login
/
service
/
github
")
}}"
style=
"color:#444;"
><i
class=
"zmdi zmdi-github zmdi-hc-4x"
></i></a>
@endif
@endif
</div>
...
...
tests/Auth/SocialAuthTest.php
View file @
f2917fc
...
...
@@ -32,4 +32,48 @@ class SocialAuthTest extends TestCase
$this
->
seeInDatabase
(
'social_accounts'
,
[
'user_id'
=>
$user
->
id
]);
}
public
function
test_social_login
()
{
$user
=
factory
(
\BookStack\User
::
class
)
->
make
();
config
([
'GOOGLE_APP_ID'
=>
'abc123'
,
'GOOGLE_APP_SECRET'
=>
'123abc'
,
'GITHUB_APP_ID'
=>
'abc123'
,
'GITHUB_APP_SECRET'
=>
'123abc'
,
'APP_URL'
=>
'http://localhost'
]);
$mockSocialite
=
Mockery
::
mock
(
'Laravel\Socialite\Contracts\Factory'
);
$this
->
app
[
'Laravel\Socialite\Contracts\Factory'
]
=
$mockSocialite
;
$mockSocialDriver
=
Mockery
::
mock
(
'Laravel\Socialite\Contracts\Provider'
);
$mockSocialUser
=
Mockery
::
mock
(
'\Laravel\Socialite\Contracts\User'
);
$mockSocialUser
->
shouldReceive
(
'getId'
)
->
twice
()
->
andReturn
(
'logintest123'
);
$mockSocialDriver
->
shouldReceive
(
'user'
)
->
twice
()
->
andReturn
(
$mockSocialUser
);
$mockSocialite
->
shouldReceive
(
'driver'
)
->
twice
()
->
with
(
'google'
)
->
andReturn
(
$mockSocialDriver
);
$mockSocialite
->
shouldReceive
(
'driver'
)
->
twice
()
->
with
(
'github'
)
->
andReturn
(
$mockSocialDriver
);
$mockSocialDriver
->
shouldReceive
(
'redirect'
)
->
twice
()
->
andReturn
(
redirect
(
'/'
));
// Test login routes
$this
->
visit
(
'/login'
)
->
seeElement
(
'#social-login-google'
)
->
click
(
'#social-login-google'
)
->
seePageIs
(
'/login'
);
// Test social callback
$this
->
visit
(
'/login/service/google/callback'
)
->
seePageIs
(
'/login'
)
->
see
(
trans
(
'errors.social_account_not_used'
,
[
'socialAccount'
=>
'Google'
]));
$this
->
visit
(
'/login'
)
->
seeElement
(
'#social-login-github'
)
->
click
(
'#social-login-github'
)
->
seePageIs
(
'/login'
);
// Test social callback with matching social account
DB
::
table
(
'social_accounts'
)
->
insert
([
'user_id'
=>
$this
->
getAdmin
()
->
id
,
'driver'
=>
'github'
,
'driver_id'
=>
'logintest123'
]);
$this
->
visit
(
'/login/service/github/callback'
)
->
seePageIs
(
'/'
);
}
}
...
...
Please
register
or
sign in
to post a comment