-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add /system/settings endpoint (SQPIT-1141) (#2903)
Currently, only brig.options.settings.setRestrictUserCreation is exposed. Please check with security before you publish more settings. Co-authored-by: fisx <[email protected]>
- Loading branch information
Showing
11 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
`GET /system/settings/unauthorized` returns a curated set of system settings from brig. The endpoint is reachable without authentication/authorization. It's meant to be used by apps to adjust their behavior (e.g. to show a registration dialog if registrations are enabled on the backend.) Currently, only the `setRestrictUserCreation` flag is exported. Other options may be added in future (in consultation with the security department.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Wire.API.SystemSettings where | ||
|
||
import Control.Lens hiding ((.=)) | ||
import qualified Data.Aeson as A | ||
import Data.Schema as Schema | ||
import qualified Data.Swagger as S | ||
import Imports hiding (head) | ||
import Servant.Swagger.Internal.Orphans () | ||
import Test.QuickCheck | ||
import Wire.Arbitrary | ||
|
||
-- | Subset of `Brig.Options.Settings` that is safe to be shown in public. | ||
-- | ||
-- Used to expose settings via the @/system/settings/unauthorized@ endpoint. | ||
-- ALWAYS CHECK WITH SECURITY IF YOU WANT TO ADD SETTINGS HERE. | ||
data SystemSettings = SystemSettings | ||
{ systemSettingsSetRestrictUserCreation :: !Bool | ||
} | ||
deriving (Eq, Show, Generic) | ||
deriving (A.ToJSON, A.FromJSON, S.ToSchema) via Schema.Schema SystemSettings | ||
deriving (Arbitrary) via (GenericUniform SystemSettings) | ||
|
||
instance Schema.ToSchema SystemSettings where | ||
schema = | ||
Schema.object "SystemSettings" $ | ||
SystemSettings | ||
<$> systemSettingsSetRestrictUserCreation | ||
Schema..= Schema.fieldWithDocModifier | ||
"setRestrictUserCreation" | ||
(description ?~ "Do not allow certain user creation flows") | ||
Schema.schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module API.SystemSettings (tests) where | ||
|
||
import Bilge | ||
import Bilge.Assert | ||
import Brig.Options | ||
import Control.Lens | ||
import qualified Data.ByteString.Char8 as BS | ||
import Imports | ||
import Network.Wai.Test as WaiTest | ||
import Test.Tasty | ||
import Test.Tasty.HUnit | ||
import Util | ||
import Wire.API.Routes.Version | ||
import Wire.API.SystemSettings | ||
|
||
tests :: Opts -> Manager -> IO TestTree | ||
tests opts m = pure $ do | ||
testGroup | ||
"settings" | ||
[ test m "GET /system/settings/unauthorized" $ testGetSettings opts | ||
] | ||
|
||
testGetSettings :: Opts -> Http () | ||
testGetSettings opts = liftIO $ do | ||
expectResultForSetting Nothing False | ||
expectResultForSetting (Just False) False | ||
expectResultForSetting (Just True) True | ||
where | ||
expectResultForSetting :: Maybe Bool -> Bool -> IO () | ||
expectResultForSetting restrictUserCreationSetting expectedRes = do | ||
let newOpts = opts & (optionSettings . restrictUserCreation) .~ restrictUserCreationSetting | ||
-- Run call in `WaiTest.Session` with an adjusted brig `Application`. I.e. | ||
-- the response is created by running the brig `Application` (with | ||
-- modified options) directly on the `Request`. No real HTTP request is | ||
-- made. This happens due to the `MonadHttp WaiTest.Session` instance. | ||
queriedSettings <- withSettingsOverrides newOpts $ getSystemSettings | ||
liftIO $ | ||
queriedSettings @?= SystemSettings expectedRes | ||
|
||
getSystemSettings :: WaiTest.Session SystemSettings | ||
getSystemSettings = | ||
responseJsonError | ||
=<< get (path (BS.pack ("/" ++ latestVersion ++ "/system/settings/unauthorized"))) | ||
<!! statusCode | ||
Bilge.Assert.=== const 200 | ||
where | ||
latestVersion :: String | ||
latestVersion = map toLower $ show (maxBound :: Version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters