11// Gateway auth bypass tests cover channel plugin paths allowed to skip gateway auth.
22import { describe , expect , it , vi } from "vitest" ;
33
4- const { loadBundledPluginPublicArtifactModuleSyncMock } = vi . hoisted ( ( ) => ( {
5- loadBundledPluginPublicArtifactModuleSyncMock : vi . fn (
6- ( { artifactBasename, dirName } : { artifactBasename : string ; dirName : string } ) => {
4+ const { tryLoadActivatedBundledPluginPublicSurfaceModuleMock } = vi . hoisted ( ( ) => ( {
5+ tryLoadActivatedBundledPluginPublicSurfaceModuleMock : vi . fn (
6+ async ( { artifactBasename, dirName } : { artifactBasename : string ; dirName : string } ) => {
77 if ( dirName === "mattermost" && artifactBasename === "gateway-auth-api.js" ) {
88 return {
99 resolveGatewayAuthBypassPaths : ( ) => [
@@ -14,6 +14,10 @@ const { loadBundledPluginPublicArtifactModuleSyncMock } = vi.hoisted(() => ({
1414 ] ,
1515 } ;
1616 }
17+ if ( dirName === "disabledchannel" ) {
18+ // Activation-gated loads return null for disabled/denied plugins.
19+ return null ;
20+ }
1721 if ( dirName === "broken" && artifactBasename === "gateway-auth-api.js" ) {
1822 throw new Error ( "broken gateway auth artifact" ) ;
1923 }
@@ -24,41 +28,51 @@ const { loadBundledPluginPublicArtifactModuleSyncMock } = vi.hoisted(() => ({
2428 ) ,
2529} ) ) ;
2630
27- vi . mock ( "../../plugins/public-surface-loader.js" , ( ) => ( {
28- loadBundledPluginPublicArtifactModuleSync : loadBundledPluginPublicArtifactModuleSyncMock ,
31+ vi . mock ( "../../plugin-sdk/facade-runtime.js" , ( ) => ( {
32+ tryLoadActivatedBundledPluginPublicSurfaceModule :
33+ tryLoadActivatedBundledPluginPublicSurfaceModuleMock ,
2934} ) ) ;
3035
3136import { resolveBundledChannelGatewayAuthBypassPaths } from "./gateway-auth-bypass.js" ;
3237
33- describe ( "bundled channel gateway auth bypass fast path" , ( ) => {
34- it ( "loads the narrow gateway auth artifact for configured channels" , ( ) => {
35- const paths = resolveBundledChannelGatewayAuthBypassPaths ( {
38+ describe ( "channel gateway auth bypass fast path" , ( ) => {
39+ it ( "loads the narrow gateway auth artifact for configured channels" , async ( ) => {
40+ const paths = await resolveBundledChannelGatewayAuthBypassPaths ( {
3641 channelId : "mattermost" ,
3742 cfg : { channels : { mattermost : { } } } ,
3843 } ) ;
3944
4045 expect ( paths ) . toEqual ( [ "/api/channels/mattermost/command" , "/api/channels/mattermost/work" ] ) ;
41- expect ( loadBundledPluginPublicArtifactModuleSyncMock ) . toHaveBeenCalledWith ( {
46+ expect ( tryLoadActivatedBundledPluginPublicSurfaceModuleMock ) . toHaveBeenCalledWith ( {
4247 dirName : "mattermost" ,
4348 artifactBasename : "gateway-auth-api.js" ,
4449 } ) ;
4550 } ) ;
4651
47- it ( "treats missing gateway auth artifacts as no bypass paths" , ( ) => {
48- expect (
52+ it ( "treats missing gateway auth artifacts as no bypass paths" , async ( ) => {
53+ await expect (
4954 resolveBundledChannelGatewayAuthBypassPaths ( {
5055 channelId : "discord" ,
5156 cfg : { channels : { discord : { } } } ,
5257 } ) ,
53- ) . toStrictEqual ( [ ] ) ;
58+ ) . resolves . toStrictEqual ( [ ] ) ;
59+ } ) ;
60+
61+ it ( "returns no bypass paths when plugin activation blocks the artifact" , async ( ) => {
62+ await expect (
63+ resolveBundledChannelGatewayAuthBypassPaths ( {
64+ channelId : "disabledchannel" ,
65+ cfg : { channels : { disabledchannel : { } } } ,
66+ } ) ,
67+ ) . resolves . toStrictEqual ( [ ] ) ;
5468 } ) ;
5569
56- it ( "surfaces errors from present gateway auth artifacts" , ( ) => {
57- expect ( ( ) =>
70+ it ( "surfaces errors from present gateway auth artifacts" , async ( ) => {
71+ await expect (
5872 resolveBundledChannelGatewayAuthBypassPaths ( {
5973 channelId : "broken" ,
6074 cfg : { channels : { broken : { } } } ,
6175 } ) ,
62- ) . toThrow ( "broken gateway auth artifact" ) ;
76+ ) . rejects . toThrow ( "broken gateway auth artifact" ) ;
6377 } ) ;
6478} ) ;
0 commit comments