@@ -285,6 +285,43 @@ testAgainstRunningApps({
285285 await u . page . unrouteAll ( ) ;
286286 } ) ;
287287
288+ test ( 'UserProfile API keys uses user ID as subject even when organization is active' , async ( { page, context } ) => {
289+ const u = createTestUtils ( { app, page, context } ) ;
290+
291+ const admin = await u . services . users . getUser ( { email : fakeAdmin . email } ) ;
292+ expect ( admin ) . toBeDefined ( ) ;
293+ const userId = admin . id ;
294+
295+ await u . po . signIn . goTo ( ) ;
296+ await u . po . signIn . waitForMounted ( ) ;
297+ await u . po . signIn . signInWithEmailAndInstantPassword ( { email : fakeAdmin . email , password : fakeAdmin . password } ) ;
298+ await u . po . expect . toBeSignedIn ( ) ;
299+
300+ await u . po . organizationSwitcher . goTo ( ) ;
301+ await u . po . organizationSwitcher . waitForMounted ( ) ;
302+ await u . po . organizationSwitcher . waitForAnOrganizationToSelected ( ) ;
303+
304+ let capturedSubject : string | null = null ;
305+ const apiKeyRequestPromise = u . page . waitForRequest ( request => {
306+ if ( request . url ( ) . includes ( 'api_keys' ) ) {
307+ const url = new URL ( request . url ( ) ) ;
308+ capturedSubject = url . searchParams . get ( 'subject' ) ;
309+ return true ;
310+ }
311+ return false ;
312+ } ) ;
313+
314+ await u . po . page . goToRelative ( '/user' ) ;
315+ await u . po . userProfile . waitForMounted ( ) ;
316+ await u . po . userProfile . switchToAPIKeysTab ( ) ;
317+
318+ await apiKeyRequestPromise ;
319+
320+ // Verify the subject parameter is the user ID, not the organization ID
321+ expect ( capturedSubject ) . toBe ( userId ) ;
322+ expect ( capturedSubject ) . not . toBe ( fakeOrganization . organization . id ) ;
323+ } ) ;
324+
288325 test ( 'standalone API keys component in user context based on user_api_keys_enabled' , async ( { page, context } ) => {
289326 const u = createTestUtils ( { app, page, context } ) ;
290327
0 commit comments