Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure integration tests use most recent API version #2695

Merged
merged 18 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5-internal/integration-test-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make test API calls point to the most recent version by default
10 changes: 5 additions & 5 deletions deploy/services-demo/conf/nginz/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ http {
proxy_pass http://brig;
}

location ~* ^/teams/invitations/([^/]*)$ {
location ~* ^(/v[0-9]+)?/teams/invitations/([^/]*)$ {
include common_response_no_zauth.conf;
proxy_pass http://brig;
}
Expand All @@ -226,7 +226,7 @@ http {

## brig authenticated endpoints

location /self {
location ~* ^(/v[0-9]+)?/self$ {
include common_response_with_zauth.conf;
proxy_pass http://brig;
}
Expand Down Expand Up @@ -261,7 +261,7 @@ http {
proxy_pass http://brig;
}

location /clients {
location ~* ^(/v[0-9]+)?/clients$ {
include common_response_with_zauth.conf;
proxy_pass http://brig;
}
Expand Down Expand Up @@ -325,7 +325,7 @@ http {
proxy_pass http://galley;
}

location ~* /legalhold/conversations/(.*) {
location ~* ^(/v[0-9]+)?/legalhold/conversations/(.*)$ {
include common_response_with_zauth.conf;
proxy_pass http://galley;
}
Expand Down Expand Up @@ -454,7 +454,7 @@ http {
proxy_pass http://gundeck;
}

location /notifications {
location ~* ^(/v[0-9]+)?/notifications$ {
include common_response_with_zauth.conf;
proxy_pass http://gundeck;
}
Expand Down
4 changes: 4 additions & 0 deletions libs/wire-api/src/Wire/API/Routes/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ instance FromHttpApiData Version where
parseHeader = first Text.pack . Aeson.eitherDecode . LBS.fromStrict
parseUrlPiece = parseHeader . Text.encodeUtf8

instance ToHttpApiData Version where
toHeader = LBS.toStrict . Aeson.encode
toUrlPiece = Text.decodeUtf8 . toHeader

supportedVersions :: [Version]
supportedVersions = [minBound .. maxBound]

Expand Down
2 changes: 1 addition & 1 deletion services/brig/test/integration/API/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ testAddKeyPackageRef brig = do

getFeatureConfig :: forall cfg m. (MonadIO m, MonadHttp m, HasCallStack, ApiFt.IsFeatureConfig cfg, KnownSymbol (ApiFt.FeatureSymbol cfg)) => (Request -> Request) -> UserId -> m ResponseLBS
getFeatureConfig galley uid = do
get $ galley . paths ["feature-configs", featureNameBS @cfg] . zUser uid
get $ apiVersion "v1" . galley . paths ["feature-configs", featureNameBS @cfg] . zUser uid

getAllFeatureConfigs :: (MonadIO m, MonadHttp m, HasCallStack) => (Request -> Request) -> UserId -> m ResponseLBS
getAllFeatureConfigs galley uid = do
Expand Down
7 changes: 4 additions & 3 deletions services/brig/test/integration/API/Metrics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ testPrometheusMetrics brig = do
const (Just "TYPE http_request_duration_seconds histogram") =~= responseBody

testMetricsEndpoint :: Brig -> Http ()
testMetricsEndpoint brig = do
let p1 = "/self"
testMetricsEndpoint brig0 = do
let brig = apiVersion "v1" . brig0
p1 = "/self"
p2 uid = "/users/" <> uid <> "/clients"
p3 = "/login"
beforeSelf <- getCount "/self" "GET"
Expand All @@ -73,7 +74,7 @@ testMetricsEndpoint brig = do
liftIO $ assertEqual "/login was called twice" (beforeProperties + 2) countProperties
where
getCount endpoint m = do
rsp <- responseBody <$> get (brig . path "i/metrics")
rsp <- responseBody <$> get (brig0 . path "i/metrics")
-- is there some responseBodyAsText function used elsewhere?
let asText = fromMaybe "" (fromByteString' (fromMaybe "" rsp))
pure $ fromRight 0 (parseOnly (parseCount endpoint m) asText)
Expand Down
4 changes: 2 additions & 2 deletions services/brig/test/integration/API/Settings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ testUsersEmailVisibleIffExpected opts brig galley viewingUserIs visibilitySettin
]
let newOpts = opts & Opt.optionSettings . Opt.emailVisibility .~ visibilitySetting
withSettingsOverrides newOpts $ do
get (brig . zUser viewerId . path "users" . queryItem "ids" uids) !!! do
get (apiVersion "v1" . brig . zUser viewerId . path "users" . queryItem "ids" uids) !!! do
const 200 === statusCode
const (Just expected) === result
where
Expand Down Expand Up @@ -155,7 +155,7 @@ testGetUserEmailShowsEmailsIffExpected opts brig galley viewingUserIs visibility
let newOpts = opts & Opt.optionSettings . Opt.emailVisibility .~ visibilitySetting
withSettingsOverrides newOpts $ do
forM_ expectations $ \(uid, expectedEmail) ->
get (brig . zUser viewerId . paths ["users", toByteString' uid]) !!! do
get (apiVersion "v1" . brig . zUser viewerId . paths ["users", toByteString' uid]) !!! do
const 200 === statusCode
const expectedEmail === emailResult
where
Expand Down
12 changes: 7 additions & 5 deletions services/brig/test/integration/API/Team.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ where

import qualified API.Search.Util as SearchUtil
import API.Team.Util
import API.User.Util as Util hiding (listConnections)
import API.User.Util as Util
import Bilge hiding (accept, head, timeout)
import qualified Bilge
import Bilge.Assert
Expand Down Expand Up @@ -218,9 +218,9 @@ testInvitationEmailLookupNginz brig nginz = do
-- expect an invitation to be found querying with email after invite
headInvitationByEmail nginz email 200

headInvitationByEmail :: Brig -> Email -> Int -> Http ()
headInvitationByEmail brig email expectedCode =
Bilge.head (brig . path "/teams/invitations/by-email" . contentJson . queryItem "email" (toByteString' email))
headInvitationByEmail :: (Request -> Request) -> Email -> Int -> Http ()
headInvitationByEmail service email expectedCode =
Bilge.head (service . path "/teams/invitations/by-email" . contentJson . queryItem "email" (toByteString' email))
!!! const expectedCode === statusCode

testInvitationTooManyPending :: Brig -> TeamSizeLimit -> Http ()
Expand Down Expand Up @@ -383,7 +383,9 @@ createAndVerifyInvitation' replacementBrigApp acceptFn invite brig galley = do
mem <- getTeamMember invitee tid galley
liftIO $ assertEqual "Member not part of the team" invitee (mem ^. Member.userId)
liftIO $ assertEqual "Member has no/wrong invitation metadata" invmeta (mem ^. Member.invitation)
conns <- listConnections invitee brig
conns <-
responseJsonError =<< listConnections brig invitee
<!! const 200 === statusCode
liftIO $ assertBool "User should have no connections" (null (clConnections conns) && not (clHasMore conns))
pure (responseJsonMaybe rsp2, invitation)

Expand Down
10 changes: 0 additions & 10 deletions services/brig/test/integration/API/Team/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import qualified Network.Wai.Utilities.Error as Error
import Test.Tasty.HUnit
import Util
import Web.Cookie (parseSetCookie, setCookieName)
import Wire.API.Connection
import Wire.API.Conversation
import Wire.API.Conversation.Protocol
import Wire.API.Conversation.Role
Expand Down Expand Up @@ -343,15 +342,6 @@ register' e t c brig =
)
)

listConnections :: HasCallStack => UserId -> Brig -> (MonadIO m, MonadHttp m, MonadThrow m) => m UserConnectionList
listConnections u brig = do
responseJsonError
=<< get
( brig
. path "connections"
. zUser u
)

getInvitation :: Brig -> InvitationCode -> (MonadIO m, MonadHttp m) => m (Maybe Invitation)
getInvitation brig c = do
r <-
Expand Down
27 changes: 15 additions & 12 deletions services/brig/test/integration/API/User/Account.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module API.User.Account
where

import qualified API.Search.Util as Search
import API.Team.Util hiding (listConnections)
import API.Team.Util
import API.User.Util
import Bilge hiding (accept, timeout)
import Bilge.Assert
Expand Down Expand Up @@ -589,11 +589,11 @@ testNonExistingUserUnqualified :: Brig -> Http ()
testNonExistingUserUnqualified brig = do
findingOne <- liftIO $ Id <$> UUID.nextRandom
foundOne <- liftIO $ Id <$> UUID.nextRandom
get (brig . paths ["users", pack $ show foundOne] . zUser findingOne)
get (apiVersion "v1" . brig . paths ["users", pack $ show foundOne] . zUser findingOne)
!!! do
const 404 === statusCode
const (Just "not-found") === fmap Error.label . responseJsonMaybe
get (brig . paths ["users", pack $ show foundOne] . zUser foundOne)
get (apiVersion "v1" . brig . paths ["users", pack $ show foundOne] . zUser foundOne)
!!! do
const 404 === statusCode
const (Just "not-found") === fmap Error.label . responseJsonMaybe
Expand All @@ -605,11 +605,11 @@ testNonExistingUser brig = do
uid2 <- liftIO $ Id <$> UUID.nextRandom
let uid = qUnqualified qself
domain = qDomain qself
get (brig . paths ["users", toByteString' domain, toByteString' uid1] . zUser uid)
get (apiVersion "v1" . brig . paths ["users", toByteString' domain, toByteString' uid1] . zUser uid)
!!! do
const 404 === statusCode
const (Just "not-found") === fmap Error.label . responseJsonMaybe
get (brig . paths ["users", toByteString' domain, toByteString' uid2] . zUser uid)
get (apiVersion "v1" . brig . paths ["users", toByteString' domain, toByteString' uid2] . zUser uid)
!!! do
const 404 === statusCode
const (Just "not-found") === fmap Error.label . responseJsonMaybe
Expand All @@ -629,7 +629,7 @@ testUserInvalidDomain brig = do
testExistingUserUnqualified :: Brig -> Http ()
testExistingUserUnqualified brig = do
uid <- userId <$> randomUser brig
get (brig . paths ["users", pack $ show uid] . zUser uid) !!! do
get (apiVersion "v1" . brig . paths ["users", pack $ show uid] . zUser uid) !!! do
const 200 === statusCode
const (Just uid)
=== ( \r -> do
Expand All @@ -643,7 +643,8 @@ testExistingUser brig = do
let uid = qUnqualified quser
domain = qDomain quser
get
( brig
( apiVersion "v1"
. brig
. zUser uid
. paths
[ "users",
Expand All @@ -664,7 +665,8 @@ testUserExistsUnqualified brig = do
qself <- userQualifiedId <$> randomUser brig
quser <- userQualifiedId <$> randomUser brig
head
( brig
( apiVersion "v1"
. brig
. paths ["users", toByteString' (qUnqualified quser)]
. zUser (qUnqualified qself)
)
Expand Down Expand Up @@ -726,7 +728,8 @@ testMultipleUsersUnqualified brig = do
(Just $ userDisplayName u3, Nothing)
]
get
( brig
( apiVersion "v1"
. brig
. zUser (userId u1)
. contentJson
. path "users"
Expand Down Expand Up @@ -794,7 +797,7 @@ testCreateUserAnonExpiry b = do
liftIO $ assertBool "Bob must be in deleted state" (fromMaybe False $ deleted resBob')
where
getProfile :: UserId -> UserId -> Http ResponseLBS
getProfile zusr uid = get (b . zUser zusr . paths ["users", toByteString' uid]) <!! const 200 === statusCode
getProfile zusr uid = get (apiVersion "v1" . b . zUser zusr . paths ["users", toByteString' uid]) <!! const 200 === statusCode
awaitExpiry :: Int -> UserId -> UserId -> Http ()
awaitExpiry n zusr uid = do
-- after expiration, a profile lookup should trigger garbage collection of ephemeral users
Expand All @@ -818,7 +821,7 @@ testCreateUserAnonExpiry b = do
field :: FromJSON a => Text -> Value -> Maybe a
field f u = u ^? key f >>= maybeFromJSON

testUserUpdate :: Brig -> Cannon -> AWS.Env -> Http ()
testUserUpdate :: HasCallStack => Brig -> Cannon -> AWS.Env -> Http ()
testUserUpdate brig cannon aws = do
aliceUser <- randomUser brig
liftIO $ Util.assertUserJournalQueue "user create alice" aws (userActivateJournaled aliceUser)
Expand Down Expand Up @@ -1749,7 +1752,7 @@ execAndAssertUserDeletion brig cannon u hdl others aws execDelete = do
Search.refreshIndex brig
-- Does not appear in search; public profile shows the user as deleted
forM_ others $ \usr -> do
get (brig . paths ["users", toByteString' uid] . zUser usr) !!! assertDeletedProfilePublic
get (apiVersion "v1" . brig . paths ["users", toByteString' uid] . zUser usr) !!! assertDeletedProfilePublic
Search.assertCan'tFind brig usr quid (fromName (userDisplayName u))
Search.assertCan'tFind brig usr quid (fromHandle hdl)
-- Email address is available again
Expand Down
Loading