Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Przemyslaw Kaminski
haskell-gargantext
Commits
3fcd27d3
Commit
3fcd27d3
authored
Nov 29, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://gitlab.iscpif.fr:20022/gargantext/haskell-gargantext
parents
28e68956
655584c0
Changes
1
Hide 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 @
3fcd27d3
...
...
@@ -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
muId
<-
getRootUsername
u
c
let
uId
=
maybe
(
panic
"API.AUTH: no user node"
)
_node_id
$
head
muId
pure
$
Valid
"token"
uId
checkAuthRequest
u
p
c
|
not
(
u
`
elem
`
arbitraryUsername
)
=
pure
InvalidUser
|
u
/=
reverse
p
=
pure
InvalidPassword
|
otherwise
=
do
muId
<-
getRootUsername
u
c
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