Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
Doorcode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Guardians of the Kretschmar Elock System
Doorcode
Commits
52cb94e5
Commit
52cb94e5
authored
Mar 04, 2020
by
Jacob Priddy
👌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Door use case tests.
parent
d79af452
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
215 additions
and
47 deletions
+215
-47
src/web/backend/app/Door.php
src/web/backend/app/Door.php
+3
-3
src/web/backend/app/Guards/DoorGuard.php
src/web/backend/app/Guards/DoorGuard.php
+5
-10
src/web/backend/app/Http/Kernel.php
src/web/backend/app/Http/Kernel.php
+0
-1
src/web/backend/app/Http/Middleware/RedirectIfAuthenticated.php
...b/backend/app/Http/Middleware/RedirectIfAuthenticated.php
+0
-27
src/web/backend/src/Gateways/Saml/InMemorySamlRepository.php
src/web/backend/src/Gateways/Saml/InMemorySamlRepository.php
+6
-2
src/web/backend/src/UseCases/Doors/Authenticate/Authenticate.php
.../backend/src/UseCases/Doors/Authenticate/Authenticate.php
+11
-4
src/web/backend/tests/Unit/Source/UseCases/Doors/Authenticate/PresenterStub.php
...Unit/Source/UseCases/Doors/Authenticate/PresenterStub.php
+31
-0
src/web/backend/tests/Unit/Source/UseCases/Doors/Authenticate/PresenterTest.php
...Unit/Source/UseCases/Doors/Authenticate/PresenterTest.php
+78
-0
src/web/backend/tests/Unit/Source/UseCases/Doors/Authenticate/UseCaseTest.php
...s/Unit/Source/UseCases/Doors/Authenticate/UseCaseTest.php
+81
-0
No files found.
src/web/backend/app/Door.php
View file @
52cb94e5
...
...
@@ -6,7 +6,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
class
Door
extends
Authenticatable
{
protected
$fillable
=
[
'*'
];
protected
$fillable
=
[
'id'
,
'name'
,
'location'
,
'created_at'
,
'updated_at'
];
protected
$guarded
=
[
];
}
src/web/backend/app/Guards/DoorGuard.php
View file @
52cb94e5
...
...
@@ -7,6 +7,7 @@ use Illuminate\Http\Request;
use
Illuminate\Auth\GuardHelpers
;
use
Illuminate\Contracts\Auth\Guard
;
use
Illuminate\Contracts\Auth\Authenticatable
;
use
Source\Exceptions\AuthenticationException
;
use
Source\UseCases\Doors\Authenticate\AuthenticateUseCase
;
use
Source\UseCases\Doors\Authenticate\TranslationPresenter
;
...
...
@@ -68,9 +69,7 @@ class DoorGuard implements Guard
$token
=
$this
->
getTokenForRequest
();
if
(
!
empty
(
$token
))
{
$user
=
$this
->
retrieveByToken
(
$token
);
}
$user
=
$this
->
retrieveByToken
(
$token
);
return
$this
->
user
=
$user
;
}
...
...
@@ -107,15 +106,11 @@ class DoorGuard implements Guard
*/
public
function
validate
(
array
$credentials
=
[])
{
if
(
empty
(
$credentials
[
$this
->
inputKey
]))
{
if
(
!
isset
(
$credentials
[
$this
->
inputKey
]))
{
return
false
;
}
if
(
$this
->
retrieveByToken
(
$credentials
[
$this
->
inputKey
]))
{
return
true
;
}
return
false
;
return
(
bool
)
$this
->
retrieveByToken
(
$credentials
[
$this
->
inputKey
]);
}
/**
...
...
@@ -136,7 +131,7 @@ class DoorGuard implements Guard
*
* @return Authenticatable|null
*/
public
function
retrieveByToken
(
string
$token
):
?Authenticatable
public
function
retrieveByToken
(
?
string
$token
):
?Authenticatable
{
$presenter
=
new
TranslationPresenter
();
...
...
src/web/backend/app/Http/Kernel.php
View file @
52cb94e5
...
...
@@ -83,7 +83,6 @@ class Kernel extends HttpKernel
'bindings'
=>
SubstituteBindings
::
class
,
'cache.headers'
=>
SetCacheHeaders
::
class
,
'can'
=>
Authorize
::
class
,
'guest'
=>
RedirectIfAuthenticated
::
class
,
'password.confirm'
=>
RequirePassword
::
class
,
'signed'
=>
ValidateSignature
::
class
,
'throttle'
=>
ThrottleRequests
::
class
,
...
...
src/web/backend/app/Http/Middleware/RedirectIfAuthenticated.php
deleted
100644 → 0
View file @
d79af452
<?php
namespace
App\Http\Middleware
;
use
Closure
;
use
Illuminate\Support\Facades\Auth
;
use
App\Providers\RouteServiceProvider
;
class
RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public
function
handle
(
$request
,
Closure
$next
,
$guard
=
null
)
{
if
(
Auth
::
guard
(
$guard
)
->
check
())
{
return
redirect
(
RouteServiceProvider
::
HOME
);
}
return
$next
(
$request
);
}
}
src/web/backend/src/Gateways/Saml/InMemorySamlRepository.php
View file @
52cb94e5
...
...
@@ -9,7 +9,7 @@ class InMemorySamlRepository implements SamlRepository
{
protected
?SamlUser
$userToLogInAs
=
null
;
protected
?SamlUser
$loggedInUser
=
null
;
protected
?SamlUser
$loggedInUser
;
protected
string
$loginUrl
;
...
...
@@ -43,7 +43,11 @@ class InMemorySamlRepository implements SamlRepository
*/
public
function
handleLogin
():
?SamlUser
{
return
$this
->
loggedInUser
;
if
(
$this
->
isAuthenticated
())
{
return
$this
->
loggedInUser
;
}
return
null
;
}
/**
...
...
src/web/backend/src/UseCases/Doors/Authenticate/Authenticate.php
View file @
52cb94e5
...
...
@@ -3,11 +3,18 @@
namespace
Source\UseCases\Doors\Authenticate
;
use
Source\Gateways\Doors\DoorsRepository
;
use
Source\Exceptions\AuthenticationException
;
class
Authenticate
implements
AuthenticateUseCase
{
/**
* @var \Source\Gateways\Doors\DoorsRepository
*/
protected
DoorsRepository
$doors
;
/**
* @param \Source\Gateways\Doors\DoorsRepository $doors
*/
public
function
__construct
(
DoorsRepository
$doors
)
{
$this
->
doors
=
$doors
;
...
...
@@ -18,11 +25,11 @@ class Authenticate implements AuthenticateUseCase
*/
public
function
check
(
Presenter
$presenter
,
?string
$token
):
void
{
if
(
!
$token
)
{
return
;
}
$found
=
null
;
$found
=
$this
->
doors
->
getByToken
(
$token
);
if
(
$token
)
{
$found
=
$this
->
doors
->
getByToken
(
$token
);
}
$response
=
new
ResponseModel
();
...
...
src/web/backend/tests/Unit/Source/UseCases/Doors/Authenticate/PresenterStub.php
0 → 100644
View file @
52cb94e5
<?php
namespace
Tests\Unit\Source\UseCases\Doors\Authenticate
;
use
App\Door
;
use
Source\UseCases\Doors\Authenticate\Presenter
;
use
Source\UseCases\Doors\Authenticate\ResponseModel
;
class
PresenterStub
implements
Presenter
{
public
ResponseModel
$response
;
protected
bool
$presenterCalled
=
false
;
public
function
present
(
ResponseModel
$responseModel
):
void
{
$this
->
presenterCalled
=
true
;
$this
->
response
=
$responseModel
;
}
public
function
wasPresenterCalled
():
bool
{
return
$this
->
presenterCalled
;
}
public
function
getViewModel
():
?Door
{
return
null
;
}
}
src/web/backend/tests/Unit/Source/UseCases/Doors/Authenticate/PresenterTest.php
0 → 100644
View file @
52cb94e5
<?php
namespace
Tests\Unit\Source\UseCases\Doors\Authenticate
;
use
Carbon\Carbon
;
use
Source\Entities\User
;
use
Source\Entities\Door
;
use
Source\Entities\Token
;
use
PHPUnit\Framework\TestCase
;
use
Source\UseCases\Doors\Authenticate\ResponseModel
;
use
Source\UseCases\Doors\Authenticate\TranslationPresenter
;
class
PresenterTest
extends
TestCase
{
/**
* @var \Source\UseCases\Doors\Authenticate\TranslationPresenter
*/
protected
TranslationPresenter
$presenter
;
/**
* @var \Source\UseCases\Doors\Authenticate\ResponseModel
*/
protected
ResponseModel
$model
;
/**
* @var \App\Door|null
*/
protected
?
\
App\Door
$response
;
public
function
setUp
():
void
{
parent
::
setUp
();
$this
->
presenter
=
new
TranslationPresenter
();
$this
->
model
=
new
ResponseModel
();
}
public
function
handleTest
():
void
{
$this
->
presenter
->
present
(
$this
->
model
);
$this
->
response
=
$this
->
presenter
->
getViewModel
();
}
/**
* @test
*/
public
function
it_presents_a_null_door
():
void
{
$this
->
model
->
setDoor
(
null
);
$this
->
handleTest
();
$this
->
assertNull
(
$this
->
response
);
}
/**
* @test
*/
public
function
it_presents_a_door
():
void
{
$door
=
new
Door
(
0
,
'location'
,
'name'
,
'token'
);
$this
->
model
->
setDoor
(
$door
);
$this
->
handleTest
();
$this
->
assertEquals
(
new
\
App\Door
([
'id'
=>
0
,
'name'
=>
'name'
,
'location'
=>
'location'
,
'created_at'
=>
null
,
'updated_at'
=>
null
,
]),
$this
->
response
);
}
}
src/web/backend/tests/Unit/Source/UseCases/Doors/Authenticate/UseCaseTest.php
0 → 100644
View file @
52cb94e5
<?php
namespace
Tests\Unit\Source\UseCases\Doors\Authenticate
;
use
Source\Entities\Door
;
use
PHPUnit\Framework\TestCase
;
use
Source\Gateways\Doors\InMemoryDoorsRepository
;
use
Source\UseCases\Doors\Authenticate\Authenticate
;
use
Source\UseCases\Doors\Authenticate\ResponseModel
;
class
UseCaseTest
extends
TestCase
{
/**
* @var \Source\Gateways\Doors\InMemoryDoorsRepository
*/
protected
InMemoryDoorsRepository
$doors
;
/**
* @var \Tests\Unit\Source\UseCases\Doors\Authenticate\PresenterStub
*/
protected
PresenterStub
$presenter
;
/**
* @var \Source\UseCases\Doors\Authenticate\ResponseModel
*/
protected
ResponseModel
$response
;
protected
Authenticate
$useCase
;
public
function
setUp
():
void
{
parent
::
setUp
();
$this
->
doors
=
new
InMemoryDoorsRepository
();
$this
->
presenter
=
new
PresenterStub
();
$this
->
useCase
=
new
Authenticate
(
$this
->
doors
);
}
/**
* @param string|null $token
*/
public
function
handleTest
(
?string
$token
):
void
{
$this
->
useCase
->
check
(
$this
->
presenter
,
$token
);
$this
->
response
=
$this
->
presenter
->
response
;
}
/**
* @test
*/
public
function
it_calls_present_on_presenter
():
void
{
$this
->
handleTest
(
null
);
$this
->
assertTrue
(
$this
->
presenter
->
wasPresenterCalled
());
}
/**
* @test
*/
public
function
it_doesnt_find_empty_token
():
void
{
$this
->
handleTest
(
null
);
$this
->
assertNull
(
$this
->
response
->
getDoor
());
}
/**
* @test
*/
public
function
it_finds_a_door
():
void
{
$door
=
$this
->
doors
->
create
(
new
Door
(
0
,
''
,
''
,
'token'
));
$this
->
handleTest
(
'token'
);
$this
->
assertEquals
(
$door
,
$this
->
response
->
getDoor
());
}
}
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