Skip to content

Commit

Permalink
Sqservices 1157 2 mf for generating SCIM token errors and renaming (#…
Browse files Browse the repository at this point in the history
…2135)

* failure responses added

* renamed code to verification_code

* added roundtrip and golden tests
  • Loading branch information
battermann authored Feb 16, 2022
1 parent 0a7f61c commit d029f9f
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 9 deletions.
4 changes: 4 additions & 0 deletions libs/wire-api/src/Wire/API/ErrorDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,7 @@ type BroadcastLimitExceeded =
"Too many users to fan out the broadcast event to."

type InvalidAction = ErrorDescription 403 "invalid-actions" "The specified actions are invalid."

type PasswordAuthenticationFailed = ErrorDescription 403 "password-authentication-failed" "Password authentication failed."

type CodeAuthenticationFailed = ErrorDescription 403 "code-authentication-failed" "Code authentication failed."
6 changes: 5 additions & 1 deletion libs/wire-api/src/Wire/API/Routes/Public/Spar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Web.Scim.Capabilities.MetaSchema as Scim.Meta
import Web.Scim.Class.Auth as Scim.Auth
import Web.Scim.Class.User as Scim.User
import Wire.API.Cookie
import Wire.API.ErrorDescription (CanThrow, CodeAuthenticationFailed, PasswordAuthenticationFailed)
import Wire.API.Routes.Public
import Wire.API.User.IdentityProvider
import Wire.API.User.Saml
Expand Down Expand Up @@ -203,7 +204,10 @@ sparResponseURI (Just tid) =

type APIScim =
OmitDocs :> "v2" :> ScimSiteAPI SparTag
:<|> "auth-tokens" :> APIScimToken
:<|> "auth-tokens"
:> CanThrow PasswordAuthenticationFailed
:> CanThrow CodeAuthenticationFailed
:> APIScimToken

type ScimSiteAPI tag = ToServantApi (ScimSite tag)

Expand Down
10 changes: 6 additions & 4 deletions libs/wire-api/src/Wire/API/User/Scim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import Web.Scim.Schema.Schema (Schema (CustomSchema))
import qualified Web.Scim.Schema.Schema as Scim
import qualified Web.Scim.Schema.User as Scim
import qualified Web.Scim.Schema.User as Scim.User
import Wire.API.Arbitrary (Arbitrary, GenericUniform (..))
import Wire.API.User.Activation
import Wire.API.User.Identity (Email)
import Wire.API.User.Profile as BT
Expand Down Expand Up @@ -370,13 +371,14 @@ data CreateScimToken = CreateScimToken
-- | User code (sent by email), for 2nd factor to 'createScimTokenPassword'
createScimTokenCode :: !(Maybe ActivationCode)
}
deriving (Eq, Show)
deriving (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform CreateScimToken)

instance A.FromJSON CreateScimToken where
parseJSON = A.withObject "CreateScimToken" $ \o -> do
createScimTokenDescr <- o A..: "description"
createScimTokenPassword <- o A..:? "password"
createScimTokenCode <- o A..:? "code"
createScimTokenCode <- o A..:? "verification_code"
pure CreateScimToken {..}

-- Used for integration tests
Expand All @@ -385,7 +387,7 @@ instance A.ToJSON CreateScimToken where
A.object
[ "description" A..= createScimTokenDescr,
"password" A..= createScimTokenPassword,
"code" A..= createScimTokenCode
"verification_code" A..= createScimTokenCode
]

-- | Type used for the response of 'APIScimTokenCreate'.
Expand Down Expand Up @@ -469,7 +471,7 @@ instance ToSchema CreateScimToken where
& properties
.~ [ ("description", textSchema),
("password", textSchema),
("code", textSchema)
("verification_code", textSchema)
]
& required .~ ["description"]

Expand Down
10 changes: 9 additions & 1 deletion libs/wire-api/test/golden/Test/Wire/API/Golden/Manual.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Test.Wire.API.Golden.Manual.ConvIdsPage
import Test.Wire.API.Golden.Manual.ConversationCoverView
import Test.Wire.API.Golden.Manual.ConversationPagingState
import Test.Wire.API.Golden.Manual.ConversationsResponse
import Test.Wire.API.Golden.Manual.CreateScimToken
import Test.Wire.API.Golden.Manual.FeatureConfigEvent
import Test.Wire.API.Golden.Manual.GetPaginatedConversationIds
import Test.Wire.API.Golden.Manual.ListConversations
Expand Down Expand Up @@ -100,5 +101,12 @@ tests =
testObjects
[(testObject_ListConversations_1, "testObject_ListConversations_1.json")],
testGroup "ConversationsResponse" $
testObjects [(testObject_ConversationsResponse_1, "testObject_ConversationsResponse_1.json")]
testObjects [(testObject_ConversationsResponse_1, "testObject_ConversationsResponse_1.json")],
testGroup "CreateScimToken" $
testObjects
[ (testObject_CreateScimToken_1, "testObject_CreateScimToken_1.json"),
(testObject_CreateScimToken_2, "testObject_CreateScimToken_2.json"),
(testObject_CreateScimToken_3, "testObject_CreateScimToken_3.json"),
(testObject_CreateScimToken_4, "testObject_CreateScimToken_4.json")
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <[email protected]>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Test.Wire.API.Golden.Manual.CreateScimToken where

import Data.Misc (PlainTextPassword (PlainTextPassword))
import Data.Text.Ascii (AsciiChars (validate))
import Imports
import Wire.API.User.Activation (ActivationCode (ActivationCode, fromActivationCode))
import Wire.API.User.Scim (CreateScimToken (..))

testObject_CreateScimToken_1 :: CreateScimToken
testObject_CreateScimToken_1 =
CreateScimToken
"description"
(Just (PlainTextPassword "very-geheim"))
(Just ((ActivationCode {fromActivationCode = fromRight undefined (validate "123456")})))

testObject_CreateScimToken_2 :: CreateScimToken
testObject_CreateScimToken_2 =
CreateScimToken
"description2"
(Just (PlainTextPassword "secret"))
Nothing

testObject_CreateScimToken_3 :: CreateScimToken
testObject_CreateScimToken_3 =
CreateScimToken
"description3"
Nothing
(Just ((ActivationCode {fromActivationCode = fromRight undefined (validate "654321")})))

testObject_CreateScimToken_4 :: CreateScimToken
testObject_CreateScimToken_4 =
CreateScimToken
"description4"
Nothing
Nothing
5 changes: 5 additions & 0 deletions libs/wire-api/test/golden/testObject_CreateScimToken_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description": "description",
"password": "very-geheim",
"verification_code": "123456"
}
5 changes: 5 additions & 0 deletions libs/wire-api/test/golden/testObject_CreateScimToken_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description": "description2",
"password": "secret",
"verification_code": null
}
5 changes: 5 additions & 0 deletions libs/wire-api/test/golden/testObject_CreateScimToken_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description": "description3",
"password": null,
"verification_code": "654321"
}
5 changes: 5 additions & 0 deletions libs/wire-api/test/golden/testObject_CreateScimToken_4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description": "description4",
"password": null,
"verification_code": null
}
2 changes: 2 additions & 0 deletions libs/wire-api/test/unit/Test/Wire/API/Roundtrip/Aeson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import qualified Wire.API.User.Identity as User.Identity
import qualified Wire.API.User.Password as User.Password
import qualified Wire.API.User.Profile as User.Profile
import qualified Wire.API.User.RichInfo as User.RichInfo
import qualified Wire.API.User.Scim as Scim
import qualified Wire.API.User.Search as User.Search
import qualified Wire.API.Wrapped as Wrapped

Expand Down Expand Up @@ -181,6 +182,7 @@ tests =
testRoundTrip @Push.Token.AppName,
testRoundTrip @Push.Token.PushToken,
testRoundTrip @Push.Token.PushTokenList,
testRoundTrip @Scim.CreateScimToken,
testRoundTrip @Team.BindingNewTeam,
testRoundTrip @Team.TeamBinding,
testRoundTrip @Team.Team,
Expand Down
1 change: 1 addition & 0 deletions libs/wire-api/wire-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ test-suite wire-api-golden-tests
Test.Wire.API.Golden.Manual.QualifiedUserClientPrekeyMap
Test.Wire.API.Golden.Manual.UserClientPrekeyMap
Test.Wire.API.Golden.Manual.UserIdList
Test.Wire.API.Golden.Manual.CreateScimToken
Test.Wire.API.Golden.Protobuf
Test.Wire.API.Golden.Runner
Paths_wire_api
Expand Down
3 changes: 0 additions & 3 deletions services/spar/test/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ instance Arbitrary ScimTokenInfo where
<*> arbitrary
<*> arbitrary

instance Arbitrary CreateScimToken where
arbitrary = CreateScimToken <$> arbitrary <*> arbitrary <*> arbitrary

instance Arbitrary CreateScimTokenResponse where
arbitrary = CreateScimTokenResponse <$> arbitrary <*> arbitrary

Expand Down

0 comments on commit d029f9f

Please sign in to comment.