Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
148
Issues
148
List
Board
Labels
Milestones
Merge Requests
11
Merge Requests
11
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
655584c0
Unverified
Commit
655584c0
authored
Nov 29, 2018
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Login: minor changes
parent
ac3de094
Pipeline
#31
failed with stage
Changes
1
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
12 deletions
+11
-12
Auth.hs
src/Gargantext/API/Auth.hs
+11
-12
No files found.
src/Gargantext/API/Auth.hs
View file @
655584c0
...
...
@@ -37,7 +37,7 @@ import Gargantext.Core.Utils.Prefix (unPrefix)
import
Gargantext.Database.Node
(
getRootUsername
)
import
Gargantext.Database.Types.Node
(
NodePoly
(
_node_id
))
import
Gargantext.Prelude
hiding
(
reverse
)
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck
(
elements
,
oneof
)
import
Test.QuickCheck.Arbitrary
(
Arbitrary
,
arbitrary
)
---------------------------------------------------
...
...
@@ -51,6 +51,7 @@ data AuthRequest = AuthRequest { _authReq_username :: Username
}
deriving
(
Generic
)
-- TODO: Use an HTTP error to wrap AuthInvalid
data
AuthResponse
=
AuthResponse
{
_authRes_valid
::
Maybe
AuthValid
,
_authRes_inval
::
Maybe
AuthInvalid
}
...
...
@@ -75,21 +76,18 @@ data CheckAuth = InvalidUser | InvalidPassword | Valid Token TreeId
deriving
(
Eq
)
arbitraryUsername
::
[
Username
]
arbitraryUsername
=
[
"user1"
,
"user2"
]
arbitraryUsername
=
[
"
gargantua"
,
"
user1"
,
"user2"
]
arbitraryPassword
::
[
Password
]
arbitraryPassword
=
map
reverse
arbitraryUsername
checkAuthRequest
::
Username
->
Password
->
Connection
->
IO
CheckAuth
checkAuthRequest
u
p
c
=
case
elem
u
arbitraryUsername
of
False
->
pure
InvalidUser
True
->
case
u
==
(
reverse
p
)
of
False
->
pure
InvalidPassword
True
->
do
checkAuthRequest
u
p
c
|
not
(
u
`
elem
`
arbitraryUsername
)
=
pure
InvalidUser
|
u
/=
reverse
p
=
pure
InvalidPassword
|
otherwise
=
do
muId
<-
getRootUsername
u
c
let
uId
=
maybe
(
panic
"API.AUTH: no user node"
)
_node_id
$
head
muId
pure
$
Valid
"token"
uId
pure
$
maybe
InvalidUser
(
Valid
"token"
.
_node_id
)
$
head
muId
auth'
::
Connection
->
AuthRequest
->
IO
AuthResponse
auth'
c
(
AuthRequest
u
p
)
=
do
...
...
@@ -112,7 +110,8 @@ instance Arbitrary AuthRequest where
$
(
deriveJSON
(
unPrefix
"_authRes_"
)
''
A
uthResponse
)
instance
ToSchema
AuthResponse
instance
Arbitrary
AuthResponse
where
arbitrary
=
AuthResponse
<$>
arbitrary
<*>
arbitrary
arbitrary
=
oneof
[
AuthResponse
Nothing
.
Just
<$>
arbitrary
,
flip
AuthResponse
Nothing
.
Just
<$>
arbitrary
]
$
(
deriveJSON
(
unPrefix
"_authInv_"
)
''
A
uthInvalid
)
instance
ToSchema
AuthInvalid
...
...
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