Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RAP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IA2
RAP
Commits
42641502
Commit
42641502
authored
4 years ago
by
Sonia Zorba
Browse files
Options
Downloads
Patches
Plain Diff
Added LoginHandlerTest
parent
46229f4e
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
classes/datalayer/UserDAO.php
+1
-1
1 addition, 1 deletion
classes/datalayer/UserDAO.php
classes/datalayer/mysql/MySQLUserDAO.php
+1
-1
1 addition, 1 deletion
classes/datalayer/mysql/MySQLUserDAO.php
tests/LoginHandlerTest.php
+157
-0
157 additions, 0 deletions
tests/LoginHandlerTest.php
with
159 additions
and
2 deletions
classes/datalayer/UserDAO.php
+
1
−
1
View file @
42641502
...
@@ -52,7 +52,7 @@ interface UserDAO {
...
@@ -52,7 +52,7 @@ interface UserDAO {
* @param type $typedId typed unique value used to search the identity in the database
* @param type $typedId typed unique value used to search the identity in the database
* @return RAP\User an user object, null if nothing was found.
* @return RAP\User an user object, null if nothing was found.
*/
*/
function
findUserByIdentity
(
$type
,
$typedId
);
function
findUserByIdentity
(
$type
,
$typedId
)
:
?User
;
/**
/**
* Retrieve a set of users matching a given search text.
* Retrieve a set of users matching a given search text.
...
...
This diff is collapsed.
Click to expand it.
classes/datalayer/mysql/MySQLUserDAO.php
+
1
−
1
View file @
42641502
...
@@ -123,7 +123,7 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO {
...
@@ -123,7 +123,7 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO {
$stmt
->
execute
();
$stmt
->
execute
();
}
}
public
function
findUserByIdentity
(
$type
,
$identifier
)
{
public
function
findUserByIdentity
(
$type
,
$identifier
)
:
?User
{
$dbh
=
$this
->
getDBHandler
();
$dbh
=
$this
->
getDBHandler
();
...
...
This diff is collapsed.
Click to expand it.
tests/LoginHandlerTest.php
0 → 100644
+
157
−
0
View file @
42641502
<?php
use
PHPUnit\Framework\TestCase
;
session_start
();
final
class
LoginHandlerTest
extends
TestCase
{
private
$locatorStub
;
private
$userDaoStub
;
private
$sessionStub
;
private
$oAuth2RequestHandler
;
private
$auditLogger
;
private
$loginHandler
;
public
function
setUp
():
void
{
$this
->
locatorStub
=
$this
->
createMock
(
\RAP\Locator
::
class
);
$this
->
locatorStub
->
method
(
'getBasePath'
)
->
willReturn
(
'http://rap-ia2'
);
$this
->
userDaoStub
=
$this
->
createMock
(
\RAP\UserDAO
::
class
);
$this
->
locatorStub
->
method
(
'getUserDAO'
)
->
willReturn
(
$this
->
userDaoStub
);
$this
->
sessionStub
=
$this
->
createMock
(
\RAP\SessionData
::
class
);
$this
->
locatorStub
->
method
(
'getSession'
)
->
willReturn
(
$this
->
sessionStub
);
$this
->
oAuth2RequestHandler
=
$this
->
createMock
(
\RAP\OAuth2RequestHandler
::
class
);
$this
->
locatorStub
->
method
(
'getOAuth2RequestHandler'
)
->
willReturn
(
$this
->
oAuth2RequestHandler
);
$this
->
auditLogger
=
$this
->
createMock
(
\Monolog\Logger
::
class
);
$this
->
locatorStub
->
method
(
'getAuditLogger'
)
->
willReturn
(
$this
->
auditLogger
);
$this
->
loginHandler
=
new
\RAP\LoginHandler
(
$this
->
locatorStub
,
'eduGAIN'
);
}
public
function
testTOUCheck
():
void
{
$redirect
=
$this
->
loginHandler
->
onIdentityDataReceived
(
'123'
,
function
(
$identity
)
{
$identity
->
email
=
'test@example.com'
;
});
$this
->
assertEquals
(
'http://rap-ia2/tou-check'
,
$redirect
);
}
public
function
testExistingUserLogin
():
void
{
$user
=
$this
->
getFakeUser
();
$this
->
assertEquals
(
'test@example.com'
,
$user
->
identities
[
0
]
->
email
);
$this
->
userDaoStub
->
method
(
'findUserByIdentity'
)
->
willReturn
(
$user
);
$this
->
oAuth2RequestHandler
->
method
(
'getRedirectResponseUrl'
)
->
willReturn
(
'http://redirect-url'
);
$this
->
sessionStub
->
method
(
'getOAuth2RequestData'
)
->
willReturn
(
new
\RAP\OAuth2RequestData
());
$this
->
userDaoStub
->
expects
(
$this
->
once
())
->
method
(
'updateIdentity'
)
->
with
(
$this
->
anything
());
$redirect
=
$this
->
loginHandler
->
onIdentityDataReceived
(
'123'
,
function
(
$identity
)
{
$identity
->
email
=
'test2@example.com'
;
});
// verify update
$this
->
assertEquals
(
'test2@example.com'
,
$user
->
identities
[
0
]
->
email
);
$this
->
assertEquals
(
'http://redirect-url'
,
$redirect
);
}
public
function
testShowConfirmJoinNewIdentity
():
void
{
$user
=
$this
->
getFakeUser
();
$this
->
sessionStub
->
method
(
'getUser'
)
->
willReturn
(
$user
);
$this
->
sessionStub
->
method
(
'getAction'
)
->
willReturn
(
'join'
);
$redirect
=
$this
->
loginHandler
->
onIdentityDataReceived
(
'456'
,
function
(
$identity
)
{
$identity
->
email
=
'test3@example.com'
;
});
$this
->
assertEquals
(
'http://rap-ia2/confirm-join'
,
$redirect
);
}
public
function
testShowConfirmJoinExistingIdentity
():
void
{
$user1
=
$this
->
getFakeUser
();
$user2
=
$this
->
getFakeUser
();
$user2
->
id
=
'2'
;
$user2
->
identities
[
0
]
->
id
=
'5'
;
$user2
->
identities
[
0
]
->
typedId
=
'456'
;
$this
->
sessionStub
->
method
(
'getUser'
)
->
willReturn
(
$user1
);
$this
->
sessionStub
->
method
(
'getAction'
)
->
willReturn
(
'join'
);
$this
->
userDaoStub
->
method
(
'findUserByIdentity'
)
->
willReturn
(
$user2
);
$redirect
=
$this
->
loginHandler
->
onIdentityDataReceived
(
'456'
,
function
(
$identity
)
{
$identity
->
email
=
'test3@example.com'
;
});
$this
->
assertEquals
(
'http://rap-ia2/confirm-join'
,
$redirect
);
}
public
function
testJoinExistingUser
():
void
{
$user
=
$this
->
getFakeUser
();
$this
->
sessionStub
->
method
(
'getUser'
)
->
willReturn
(
$user
);
$this
->
sessionStub
->
method
(
'getAction'
)
->
willReturn
(
'join'
);
$userToJoin
=
$this
->
getFakeUser
();
$userToJoin
->
id
=
'456'
;
$redirect
=
$this
->
loginHandler
->
getAfterLoginRedirect
(
$userToJoin
);
$this
->
assertEquals
(
'http://rap-ia2/account'
,
$redirect
);
}
public
function
testJoinNewIdentity
():
void
{
$user
=
$this
->
getFakeUser
();
$this
->
sessionStub
->
method
(
'getUser'
)
->
willReturn
(
$user
);
$this
->
sessionStub
->
method
(
'getAction'
)
->
willReturn
(
'join'
);
$userToJoin
=
$this
->
getFakeUser
();
// new identity
$userToJoin
->
id
=
null
;
$redirect
=
$this
->
loginHandler
->
getAfterLoginRedirect
(
$userToJoin
);
$this
->
assertEquals
(
'http://rap-ia2/account'
,
$redirect
);
}
public
function
testJoinAlreadyJoinedUser
():
void
{
// go to account page without joining
$user
=
$this
->
getFakeUser
();
$this
->
sessionStub
->
method
(
'getAction'
)
->
willReturn
(
'join'
);
$this
->
userDaoStub
->
method
(
'findUserByIdentity'
)
->
willReturn
(
$user
);
$redirect
=
$this
->
loginHandler
->
onIdentityDataReceived
(
'123'
,
function
(
$identity
)
{
$identity
->
email
=
'test@example.com'
;
});
$this
->
assertEquals
(
'http://rap-ia2/account'
,
$redirect
);
}
private
function
getFakeUser
():
\RAP\User
{
$user
=
new
\RAP\User
();
$user
->
id
=
'1'
;
$identity
=
new
\RAP\Identity
(
'eduGAIN'
);
$identity
->
email
=
'test@example.com'
;
$identity
->
id
=
'4'
;
$identity
->
typedId
=
'123'
;
$user
->
addIdentity
(
$identity
);
return
$user
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment