Skip to content
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
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,9 @@ upload-bombon:
openapi-validate:
@echo -e "Make sure you are running the backend in another terminal (make cr)\n"
vacuum lint -a -d -e <(curl http://localhost:8082/v7/api/swagger.json)
# vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/cannon-swagger.json)
# vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/cargohold-swagger.json)
# vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/spar-swagger.json)
# vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/gundeck-swagger.json)
# vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/brig-swagger.json)
# vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/galley-swagger.json)
vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/cannon-swagger.json)
vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/cargohold-swagger.json)
vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/spar-swagger.json)
vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/gundeck-swagger.json)
vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/brig-swagger.json)
vacuum lint -a -d -e <(curl http://localhost:8082/api-internal/swagger-ui/galley-swagger.json)
1 change: 1 addition & 0 deletions changelog.d/5-internal/fix-galley-overlaps
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix overlapping paths errors in galley's internal API
30 changes: 27 additions & 3 deletions integration/test/Test/Swagger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,41 @@ testSwaggerToc = do
html :: String
html = "<html><head></head><body><h2>please pick an api version</h2><a href=\"/v0/api/swagger-ui/\">/v0/api/swagger-ui/</a><br><a href=\"/v1/api/swagger-ui/\">/v1/api/swagger-ui/</a><br><a href=\"/v2/api/swagger-ui/\">/v2/api/swagger-ui/</a><br><a href=\"/v3/api/swagger-ui/\">/v3/api/swagger-ui/</a><br><a href=\"/v4/api/swagger-ui/\">/v4/api/swagger-ui/</a><br><a href=\"/v5/api/swagger-ui/\">/v5/api/swagger-ui/</a><br><a href=\"/v6/api/swagger-ui/\">/v6/api/swagger-ui/</a><br><a href=\"/v7/api/swagger-ui/\">/v7/api/swagger-ui/</a><br></body>"

data Swagger = SwaggerPublic | SwaggerInternal Service

instance TestCases Swagger where
mkTestCases =
pure
[ MkTestCase "[swagger=ibrig]" (SwaggerInternal Brig),
MkTestCase "[swagger=icannon]" (SwaggerInternal Cannon),
MkTestCase "[swagger=icargohold]" (SwaggerInternal Cargohold),
MkTestCase "[swagger=igalley]" (SwaggerInternal Galley),
MkTestCase "[swagger=igundeck]" (SwaggerInternal Gundeck),
MkTestCase "[swagger=ispar]" (SwaggerInternal Spar),
MkTestCase "[swagger=public]" SwaggerPublic
]

-- | This runs the swagger linter [vacuum](https://quobix.com/vacuum/).
--
-- The reason for adding the linter in the integration tests, and not in the lint job, is that
-- it calls brig for the swagger docs it validates, but no running brig during linting.
--
-- There is also a make rule that does this, for convenience in your develop
-- flow. Make sure that brig is running before using the make rule.
testSwaggerLint :: (HasCallStack) => App ()
testSwaggerLint = do
testSwaggerLint :: (HasCallStack) => Swagger -> App ()
testSwaggerLint sw = do
withSystemTempDirectory "swagger" $ \tmp -> do
req <- baseRequest OwnDomain Brig Versioned $ joinHttpPath ["api", "swagger.json"]
req <- case sw of
SwaggerPublic ->
baseRequest OwnDomain Brig Versioned
$ joinHttpPath ["api", "swagger.json"]
(SwaggerInternal service) ->
baseRequest OwnDomain Brig Unversioned
$ joinHttpPath
[ "api-internal",
"swagger-ui",
serviceName service <> "-swagger.json"
]
swagger <- submit "GET" req >>= getBody 200
liftIO $ B.writeFile (tmp </> "swagger.json") swagger
let cmd = shell $ "vacuum lint -a -d -e " <> (tmp </> "swagger.json")
Expand Down
33 changes: 3 additions & 30 deletions libs/wire-api/src/Wire/API/Routes/Internal/Galley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ type IConversationAPI =
Named
"conversation-get-member"
( "conversations"
:> Capture "cnv" ConvId
:> QualifiedCapture "cnv" ConvId
:> "members"
:> Capture "usr" UserId
:> Get '[JSON] (Maybe Member)
Expand All @@ -408,16 +408,6 @@ type IConversationAPI =
:> "v2"
:> Put '[JSON] Conversation
)
:<|> Named
"conversation-block-unqualified"
( CanThrow 'InvalidOperation
:> CanThrow 'ConvNotFound
:> ZUser
:> "conversations"
:> Capture "cnv" ConvId
:> "block"
:> Put '[JSON] ()
)
:<|> Named
"conversation-block"
( CanThrow 'InvalidOperation
Expand All @@ -432,21 +422,6 @@ type IConversationAPI =
-- - MemberJoin event to you, if the conversation existed and had < 2 members before
-- - MemberJoin event to other, if the conversation existed and only the other was member
-- before
:<|> Named
"conversation-unblock-unqualified"
( CanThrow 'InvalidOperation
:> CanThrow 'ConvNotFound
:> ZLocalUser
:> ZOptConn
:> "conversations"
:> Capture "cnv" ConvId
:> "unblock"
:> Put '[JSON] Conversation
)
-- This endpoint can lead to the following events being sent:
-- - MemberJoin event to you, if the conversation existed and had < 2 members before
-- - MemberJoin event to other, if the conversation existed and only the other was member
-- before
:<|> Named
"conversation-unblock"
( CanThrow 'InvalidOperation
Expand All @@ -470,8 +445,7 @@ type IConversationAPI =
"conversation-mls-one-to-one"
( CanThrow 'NotConnected
:> CanThrow 'MLSNotEnabled
:> "conversations"
:> "mls-one2one"
:> "mls-one2one-conversations"
:> ZLocalUser
:> QualifiedCapture "user" UserId
:> Get '[JSON] Conversation
Expand All @@ -481,8 +455,7 @@ type IConversationAPI =
( CanThrow 'NotConnected
:> CanThrow 'MLSNotEnabled
:> ZLocalUser
:> "conversations"
:> "mls-one2one"
:> "mls-one2one-conversations"
:> QualifiedCapture "user" UserId
:> "established"
:> Get '[JSON] Bool
Expand Down
3 changes: 1 addition & 2 deletions libs/wire-subsystems/src/Wire/GalleyAPIAccess/Rpc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ checkMLSOne2OneEstablished self (Qualified other otherDomain) = do
method GET
. paths
[ "i",
"conversations",
"mls-one2one",
"mls-one2one-conversations",
toByteString' otherDomain,
toByteString' other,
"established"
Expand Down
9 changes: 8 additions & 1 deletion services/brig/test/integration/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,14 @@ isMember g usr cnv = do
res <-
get $
g
. paths ["i", "conversations", toByteString' cnv, "members", toByteString' (tUnqualified usr)]
. paths
[ "i",
"conversations",
toByteString' (tDomain usr),
toByteString' cnv,
"members",
toByteString' (tUnqualified usr)
]
. expect2xx
case responseJsonMaybe res of
Nothing -> pure False
Expand Down
2 changes: 0 additions & 2 deletions services/galley/src/Galley/API/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ conversationAPI :: API IConversationAPI GalleyEffects
conversationAPI =
mkNamedAPI @"conversation-get-member" Query.internalGetMember
<@> mkNamedAPI @"conversation-accept-v2" Update.acceptConv
<@> mkNamedAPI @"conversation-block-unqualified" Update.blockConvUnqualified
<@> mkNamedAPI @"conversation-block" Update.blockConv
<@> mkNamedAPI @"conversation-unblock-unqualified" Update.unblockConvUnqualified
<@> mkNamedAPI @"conversation-unblock" Update.unblockConv
<@> mkNamedAPI @"conversation-meta" Query.getConversationMeta
<@> mkNamedAPI @"conversation-mls-one-to-one" Query.getMLSOne2OneConversationInternal
Expand Down
8 changes: 5 additions & 3 deletions services/galley/src/Galley/API/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -590,15 +590,17 @@ iterateConversations luid pageSize handleConvs = go Nothing

internalGetMember ::
( Member ConversationStore r,
Member (Error FederationError) r,
Member (Input (Local ())) r,
Member MemberStore r
) =>
ConvId ->
Qualified ConvId ->
UserId ->
Sem r (Maybe Public.Member)
internalGetMember cnv usr = do
internalGetMember qcnv usr = do
lusr <- qualifyLocal usr
getLocalSelf lusr cnv
lcnv <- ensureLocal lusr qcnv
getLocalSelf lusr (tUnqualified lcnv)

getLocalSelf ::
( Member ConversationStore r,
Expand Down
59 changes: 52 additions & 7 deletions services/galley/test/integration/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2067,10 +2067,19 @@ postRepeatConnectConvCancel = do
where
cancel u c = do
g <- viewGalley
let cnvId = qUnqualified . cnvQualifiedId
put (g . paths ["/i/conversations", toByteString' (cnvId c), "block"] . zUser u)
let qConvId = cnvQualifiedId c
put
( g
. paths
[ "/i/conversations",
toByteString' (qDomain qConvId),
toByteString' (qUnqualified qConvId),
"block"
]
. zUser u
)
!!! const 200 === statusCode
getConv u (cnvId c) !!! const 403 === statusCode
getConv u (qUnqualified qConvId) !!! const 403 === statusCode

putBlockConvOk :: TestM ()
putBlockConvOk = do
Expand All @@ -2082,23 +2091,59 @@ putBlockConvOk = do
let convId = qUnqualified qconvId
getConvQualified alice qconvId !!! const 200 === statusCode
getConvQualified bob qconvId !!! const 403 === statusCode
put (g . paths ["/i/conversations", toByteString' convId, "block"] . zUser bob)
put
( g
. paths
[ "/i/conversations",
toByteString' (qDomain qconvId),
toByteString' convId,
"block"
]
. zUser bob
)
!!! const 200 === statusCode
-- A is still the only member of the 1-1
getConvQualified alice qconvId !!! do
const 200 === statusCode
const (cnvMembers conv) === cnvMembers . responseJsonUnsafeWithMsg "conversation"
-- B accepts the conversation by unblocking
put (g . paths ["/i/conversations", toByteString' convId, "unblock"] . zUser bob)
put
( g
. paths
[ "/i/conversations",
toByteString' (qDomain qconvId),
toByteString' convId,
"unblock"
]
. zUser bob
)
!!! const 200 === statusCode
getConvQualified bob qconvId !!! const 200 === statusCode
-- B blocks A in the 1-1
put (g . paths ["/i/conversations", toByteString' convId, "block"] . zUser bob)
put
( g
. paths
[ "/i/conversations",
toByteString' (qDomain qconvId),
toByteString' convId,
"block"
]
. zUser bob
)
!!! const 200 === statusCode
-- B no longer sees the 1-1
getConvQualified bob qconvId !!! const 403 === statusCode
-- B unblocks A in the 1-1
put (g . paths ["/i/conversations", toByteString' convId, "unblock"] . zUser bob)
put
( g
. paths
[ "/i/conversations",
toByteString' (qDomain qconvId),
toByteString' convId,
"unblock"
]
. zUser bob
)
!!! const 200 === statusCode
-- B sees the blocked 1-1 again
getConvQualified bob qconvId !!! do
Expand Down