Skip to content

Commit

Permalink
[fix] apply changes asked for by Paolo and Akshay
Browse files Browse the repository at this point in the history
- make code that was messed up by hlint easier to read
- add some documentation to the nix code
  • Loading branch information
MangoIV committed Nov 14, 2023
1 parent 70b2add commit a6100d3
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 44 deletions.
7 changes: 7 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ package zauth
package fedcalls
ghc-options: -Werror

-- NOTE:
-- - these packages are not provided by nix, reason being, that
-- there is a bug in the nixpkgs haskell compatibility which
-- makes it such that they cannot be installed by the nixpkgs code
-- - these packages have bounds that are justified with their current
-- dependency set, however, we have updated their dependencies, such
-- that they work with newer base and ghc (api) versions
allow-newer:
, proto-lens-protoc:base
, proto-lens-protoc:ghc
11 changes: 3 additions & 8 deletions integration/test/Testlib/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,9 @@ readServiceConfig = readServiceConfig' . configName

readServiceConfig' :: String -> App Value
readServiceConfig' srvName = do
cfgFile <-
asks
( ( \case
Nothing -> "/etc/wire" </> srvName </> "conf" </> (srvName <> ".yaml")
Just p -> p </> srvName </> (srvName <> ".integration.yaml")
)
. (.servicesCwdBase)
)
cfgFile <- asks \env -> case env.servicesCwdBase of
Nothing -> "/etc/wire" </> srvName </> "conf" </> (srvName <> ".yaml")
Just p -> p </> srvName </> (srvName <> ".integration.yaml")

eith <- liftIO (Yaml.decodeFileEither cfgFile)
case eith of
Expand Down
27 changes: 11 additions & 16 deletions integration/test/Testlib/ModService.hs
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,10 @@ startProcess' domain execName config = do
tempFile <- liftIO $ writeTempFile "/tmp" (execName <> "-" <> domain <> "-" <> ".yaml") (cs $ Yaml.encode config)

(cwd, exe) <-
asks
( ( \case
Nothing -> (Nothing, execName)
Just dir ->
(Just (dir </> execName), "../../dist" </> execName)
)
. (.servicesCwdBase)
)
asks \env -> case env.servicesCwdBase of
Nothing -> (Nothing, execName)
Just dir ->
(Just (dir </> execName), "../../dist" </> execName)

(_, Just stdoutHdl, Just stderrHdl, ph) <- liftIO $ createProcess (proc exe ["-c", tempFile]) {cwd = cwd, std_out = CreatePipe, std_err = CreatePipe}
let prefix = "[" <> execName <> "@" <> domain <> "] "
Expand Down Expand Up @@ -549,14 +545,13 @@ server 127.0.0.1:{port} max_fails=3 weight=1;
(serviceName Spar, sm.spar.port),
("proxy", sm.proxy.port)
]
( \case
(srv, p) -> do
let upstream =
upstreamTemplate
& Text.replace "{name}" (cs $ srv)
& Text.replace "{port}" (cs $ show p)
liftIO $ appendFile upstreamsCfg (cs upstream)
)
\case
(srv, p) -> do
let upstream =
upstreamTemplate
& Text.replace "{name}" (cs $ srv)
& Text.replace "{port}" (cs $ show p)
liftIO $ appendFile upstreamsCfg (cs upstream)

startNginz :: String -> FilePath -> FilePath -> App ProcessHandle
startNginz domain conf workingDir = do
Expand Down
11 changes: 3 additions & 8 deletions integration/test/Testlib/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,9 @@ createGlobalEnv cfg = do
liftIO . runAppWithEnv env $ do
config <- readServiceConfig Galley
relPath <- config %. "settings.mlsPrivateKeyPaths.removal.ed25519" & asString
path <-
asks
( ( \case
Nothing -> relPath
Just dir -> dir </> "galley" </> relPath
)
. ((.servicesCwdBase))
)
path <- asks \env' -> case env'.servicesCwdBase of
Nothing -> relPath
Just dir -> dir </> "galley" </> relPath
bs <- liftIO $ B.readFile path
pems <- case pemParseBS bs of
Left err -> assertFailure $ "Could not parse removal key PEM: " <> err
Expand Down
1 change: 1 addition & 0 deletions nix/haskell-pins.nix
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ let
};
};

# PR at https://github.com/google/ghc-source-gen/pull/102
ghc-source-gen = {
version = "0.4.4.0";
src = pkgs.fetchFromGitHub {
Expand Down
2 changes: 1 addition & 1 deletion nix/manual-overrides.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ libsodium, protobuf, hlib, mls-test-cli, fetchpatch, pkgs }:
{ libsodium, protobuf, hlib, mls-test-cli, fetchpatch, ... }:
# FUTUREWORK: Figure out a way to detect if some of these packages are not
# actually marked broken, so we can cleanup this file on every nixpkgs bump.
hself: hsuper: {
Expand Down
2 changes: 1 addition & 1 deletion nix/wire-server.nix
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ in
haskellPackages = hPkgs localModsEnableAll;
haskellPackagesUnoptimizedNoDocs = hPkgs localModsOnlyTests;
allLocalPackages = pkgs.symlinkJoin {
name = "all-local-packages";
name = "all-local-packages";
paths = map (e: (hPkgs localModsEnableAll).${e}) wireServerPackages;
};

Expand Down
4 changes: 3 additions & 1 deletion services/galley/test/integration/API/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,9 @@ testSelfConversationList isBelowV3 = do
responseJsonError
=<< listEndpoint u Nothing (Just 100)
<!! const 200 === statusCode
pure $ foldr ((<|>) . guard . isMLSSelf u) Nothing (mtpResults convIds)
pure . getAlt $
foldMap (Alt . guard . isMLSSelf u) $
mtpResults convIds

getConvPageV2 u s c = do
g <- view tsUnversionedGalley
Expand Down
25 changes: 22 additions & 3 deletions services/galley/test/integration/API/Teams/LegalHold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Brig.Types.Intra (UserSet (..))
import Brig.Types.Test.Arbitrary ()
import Brig.Types.User.Event qualified as Ev
import Cassandra.Exec qualified as Cql
import Control.Category ((>>>))
import Control.Concurrent.Chan
import Control.Lens hiding ((#))
import Data.Id
Expand Down Expand Up @@ -724,7 +725,13 @@ testOldClientsBlockDeviceHandshake = do
UserLegalHoldStatusResponse userStatus _ _ <- getUserStatusTyped uid tid
liftIO $ assertEqual "approving should change status" UserLegalHoldEnabled userStatus
getInternalClientsFull (UserSet $ Set.singleton uid)
<&> clientId . head . Set.toList . Set.unions . Map.elems . userClientsFull
<&> do
userClientsFull
>>> Map.elems
>>> Set.unions
>>> Set.toList
>>> head
>>> clientId

putLHWhitelistTeam tid !!! const 200 === statusCode

Expand Down Expand Up @@ -800,7 +807,13 @@ testNoConsentBlockOne2OneConv connectFirst teamPeer approveLH testPendingConnect
if approveLH
then
getInternalClientsFull (UserSet $ Set.singleton legalholder)
<&> fmap clientId . listToMaybe . Set.toList . Set.unions . Map.elems . userClientsFull
<&> do
userClientsFull
>>> Map.elems
>>> Set.unions
>>> Set.toList
>>> listToMaybe
>>> fmap clientId
else pure Nothing

doDisableLH :: HasCallStack => TestM ()
Expand Down Expand Up @@ -1117,7 +1130,13 @@ testClaimKeys testcase = do
UserLegalHoldStatusResponse userStatus _ _ <- getUserStatusTyped uid team
liftIO $ assertEqual "approving should change status" UserLegalHoldEnabled userStatus
getInternalClientsFull (UserSet $ Set.singleton uid)
<&> clientId . head . Set.toList . Set.unions . Map.elems . userClientsFull
<&> do
userClientsFull
>>> Map.elems
>>> Set.unions
>>> Set.toList
>>> head
>>> clientId

let makePeerClient :: TestM ()
makePeerClient = case testcase of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Brig.Types.Intra (UserSet (..))
import Brig.Types.Test.Arbitrary ()
import Brig.Types.User.Event qualified as Ev
import Cassandra.Exec qualified as Cql
import Control.Category ((>>>))
import Control.Concurrent.Chan
import Control.Lens
import Data.Id
Expand Down Expand Up @@ -648,7 +649,13 @@ testOldClientsBlockDeviceHandshake = do
UserLegalHoldStatusResponse userStatus _ _ <- getUserStatusTyped uid tid
liftIO $ assertEqual "approving should change status" UserLegalHoldEnabled userStatus
getInternalClientsFull (UserSet $ Set.singleton uid)
<&> clientId . head . Set.toList . Set.unions . Map.elems . userClientsFull
<&> do
userClientsFull
>>> Map.elems
>>> Set.unions
>>> Set.toList
>>> head
>>> clientId

withDummyTestServiceForTeam' legalholder tid $ \_ _chan -> do
grantConsent tid legalholder
Expand Down Expand Up @@ -720,7 +727,13 @@ testClaimKeys testcase = do
UserLegalHoldStatusResponse userStatus _ _ <- getUserStatusTyped uid team
liftIO $ assertEqual "approving should change status" UserLegalHoldEnabled userStatus
getInternalClientsFull (UserSet $ Set.singleton uid)
<&> clientId . head . Set.toList . Set.unions . Map.elems . userClientsFull
<&> do
userClientsFull
>>> Map.elems
>>> Set.unions
>>> Set.toList
>>> head
>>> clientId

let makePeerClient :: TestM ()
makePeerClient = case testcase of
Expand Down
6 changes: 5 additions & 1 deletion services/gundeck/src/Gundeck/Aws.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import Amazonka.SNS.Lens qualified as SNS
import Amazonka.SQS qualified as SQS
import Amazonka.SQS.Lens qualified as SQS
import Amazonka.SQS.Types
import Control.Category ((>>>))
import Control.Error hiding (err, isRight)
import Control.Lens hiding ((.=))
import Control.Monad.Catch
Expand Down Expand Up @@ -163,7 +164,10 @@ mkEnv lgr opts mgr = do
mkEndpoint svc e = AWS.setEndpoint (e ^. awsSecure) (e ^. awsHost) (e ^. awsPort) svc
mkAwsEnv g sqs sns = do
baseEnv <-
AWS.newEnv AWS.discover <&> AWS.configureService (sns & set AWS.service_timeout (Just (AWS.Seconds 5))) . AWS.configureService sqs
AWS.newEnv AWS.discover
<&> do
AWS.configureService sqs
>>> AWS.configureService (sns & set AWS.service_timeout (Just (AWS.Seconds 5)))
pure $
baseEnv
{ AWS.logger = awsLogger g,
Expand Down
3 changes: 0 additions & 3 deletions services/spar/src/Spar/Scim/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,6 @@ deleteScimUser tokeninfo@ScimTokenInfo {stiTeam, stiIdP} uid =
-- (because that owner won't be managed by SCIM in the first place), but if it ever becomes
-- possible, we should do a check here and prohibit it.
unless (userTeam brigUser == Just stiTeam) $
-- users from other teams get you a 404.
-- users from other teams get you a 404.

-- users from other teams get you a 404.
throwError $
Scim.notFound "user" (idToText uid)
Expand Down

0 comments on commit a6100d3

Please sign in to comment.