@@ -7,17 +7,11 @@ import {
77 setLastSeenAuthMethod ,
88 setLastSeenUserIdAfterAuth ,
99} from './session.js'
10- import {
11- exchangeAccessForApplicationTokens ,
12- exchangeCustomPartnerToken ,
13- refreshAccessToken ,
14- InvalidGrantError ,
15- } from './session/exchange.js'
10+ import { exchangeCustomPartnerToken , refreshAccessToken , InvalidGrantError } from './session/exchange.js'
1611import { allDefaultScopes } from './session/scopes.js'
1712import { store as storeSessions , fetch as fetchSessions , remove as secureRemove } from './session/store.js'
18- import { ApplicationToken , IdentityToken , Sessions } from './session/schema.js'
13+ import { IdentityToken , Sessions } from './session/schema.js'
1914import { validateSession } from './session/validate.js'
20- import { applicationId } from './session/identity.js'
2115import { pollForDeviceAuthorization , requestDeviceAuthorization } from './session/device-authorization.js'
2216import { getCurrentSessionId } from './conf-store.js'
2317import * as fqdnModule from '../../public/node/context/fqdn.js'
@@ -56,26 +50,9 @@ const validTokens: OAuthSession = {
5650 userId,
5751}
5852
59- const appTokens : Record < string , ApplicationToken > = { }
60-
61- const partnersToken : ApplicationToken = {
62- accessToken : 'custom_partners_token' ,
63- expiresAt : futureDate ,
64- scopes : [ 'scope2' ] ,
65- }
66-
6753const fqdn = 'fqdn.com'
6854
6955const validSessions : Sessions = {
70- [ fqdn ] : {
71- [ userId ] : {
72- identity : validIdentityToken ,
73- applications : appTokens ,
74- } ,
75- } ,
76- }
77-
78- const invalidSessions : Sessions = {
7956 [ fqdn ] : {
8057 [ userId ] : {
8158 identity : validIdentityToken ,
@@ -85,7 +62,6 @@ const invalidSessions: Sessions = {
8562}
8663
8764vi . mock ( '../../public/node/context/local.js' )
88- vi . mock ( './session/identity' )
8965vi . mock ( './session/authorize' )
9066vi . mock ( './session/exchange' )
9167vi . mock ( './session/scopes' )
@@ -101,11 +77,9 @@ vi.mock('../../public/node/system.js')
10177
10278beforeEach ( ( ) => {
10379 vi . spyOn ( fqdnModule , 'identityFqdn' ) . mockResolvedValue ( fqdn )
104- vi . mocked ( exchangeAccessForApplicationTokens ) . mockResolvedValue ( appTokens )
10580 vi . mocked ( refreshAccessToken ) . mockResolvedValue ( validIdentityToken )
106- vi . mocked ( applicationId ) . mockImplementation ( ( app ) => app )
10781 vi . mocked ( exchangeCustomPartnerToken ) . mockResolvedValue ( {
108- accessToken : partnersToken . accessToken ,
82+ accessToken : 'custom_partners_token' ,
10983 userId : validIdentityToken . userId ,
11084 } )
11185 vi . mocked ( partnersRequest ) . mockResolvedValue ( undefined )
@@ -140,7 +114,6 @@ describe('ensureAuthenticated when previous session is invalid', () => {
140114 const got = await ensureAuthenticated ( defaultApplications )
141115
142116 // Then
143- expect ( exchangeAccessForApplicationTokens ) . not . toBeCalled ( )
144117 expect ( refreshAccessToken ) . not . toBeCalled ( )
145118 expect ( businessPlatformRequest ) . toHaveBeenCalled ( )
146119 expect ( storeSessions ) . toHaveBeenCalledOnce ( )
@@ -180,9 +153,9 @@ The CLI is currently unable to prompt for reauthentication.`,
180153 test ( 'executes complete auth flow if session is for a different fqdn' , async ( ) => {
181154 // Given
182155 vi . mocked ( validateSession ) . mockResolvedValueOnce ( 'needs_full_auth' )
183- vi . mocked ( fetchSessions ) . mockResolvedValue ( invalidSessions )
156+ vi . mocked ( fetchSessions ) . mockResolvedValue ( validSessions )
184157 const expectedSessions = {
185- ...invalidSessions ,
158+ ...validSessions ,
186159 [ fqdn ] : {
187160 [ userId ] : {
188161 identity : {
@@ -198,7 +171,7 @@ The CLI is currently unable to prompt for reauthentication.`,
198171 const got = await ensureAuthenticated ( defaultApplications )
199172
200173 // Then
201- expect ( exchangeAccessForApplicationTokens ) . not . toBeCalled ( )
174+
202175 expect ( refreshAccessToken ) . not . toBeCalled ( )
203176 expect ( storeSessions ) . toBeCalledWith ( expectedSessions )
204177 expect ( got ) . toEqual ( validTokens )
@@ -217,7 +190,7 @@ The CLI is currently unable to prompt for reauthentication.`,
217190 const got = await ensureAuthenticated ( defaultApplications )
218191
219192 // Then
220- expect ( exchangeAccessForApplicationTokens ) . not . toBeCalled ( )
193+
221194 expect ( businessPlatformRequest ) . toHaveBeenCalled ( )
222195 expect ( storeSessions ) . toHaveBeenCalledOnce ( )
223196
@@ -253,7 +226,7 @@ The CLI is currently unable to prompt for reauthentication.`,
253226 const got = await ensureAuthenticated ( defaultApplications )
254227
255228 // Then
256- expect ( exchangeAccessForApplicationTokens ) . not . toBeCalled ( )
229+
257230 expect ( refreshAccessToken ) . not . toBeCalled ( )
258231 expect ( businessPlatformRequest ) . toHaveBeenCalled ( )
259232 expect ( storeSessions ) . toHaveBeenCalledOnce ( )
@@ -279,7 +252,7 @@ describe('when existing session is valid', () => {
279252 const got = await ensureAuthenticated ( defaultApplications )
280253
281254 // Then
282- expect ( exchangeAccessForApplicationTokens ) . not . toBeCalled ( )
255+
283256 expect ( refreshAccessToken ) . not . toBeCalled ( )
284257 expect ( got ) . toEqual ( validTokens )
285258 await expect ( getLastSeenUserIdAfterAuth ( ) ) . resolves . toBe ( '1234-5678' )
@@ -303,7 +276,7 @@ describe('when existing session is valid', () => {
303276 const got = await ensureAuthenticated ( defaultApplications )
304277
305278 // Then
306- expect ( exchangeAccessForApplicationTokens ) . not . toBeCalled ( )
279+
307280 expect ( refreshAccessToken ) . not . toBeCalled ( )
308281 expect ( got ) . toEqual ( expected )
309282 await expect ( getLastSeenUserIdAfterAuth ( ) ) . resolves . toBe ( '1234-5678' )
@@ -321,7 +294,7 @@ describe('when existing session is valid', () => {
321294
322295 // Then
323296 expect ( refreshAccessToken ) . toBeCalled ( )
324- expect ( exchangeAccessForApplicationTokens ) . not . toBeCalled ( )
297+
325298 const expectedSessions = {
326299 [ fqdn ] : {
327300 [ userId ] : {
@@ -349,7 +322,7 @@ describe('when existing session is expired', () => {
349322
350323 // Then
351324 expect ( refreshAccessToken ) . toBeCalled ( )
352- expect ( exchangeAccessForApplicationTokens ) . not . toBeCalled ( )
325+
353326 const expectedSessions = {
354327 [ fqdn ] : {
355328 [ userId ] : {
@@ -378,7 +351,7 @@ describe('when existing session is expired', () => {
378351
379352 // Then
380353 expect ( refreshAccessToken ) . toBeCalled ( )
381- expect ( exchangeAccessForApplicationTokens ) . not . toBeCalled ( )
354+
382355 expect ( businessPlatformRequest ) . toHaveBeenCalled ( )
383356 expect ( storeSessions ) . toHaveBeenCalledOnce ( )
384357
0 commit comments