Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(amplify-appsync-simulator): fixed app sync simulator util auth ty…
…pe mock (#8451)
- Loading branch information
Showing
9 changed files
with
124 additions
and
8 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
packages/amplify-appsync-simulator/src/__tests__/velocity/util/auth-utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { create } from '../../../velocity/util/index'; | ||
import { GraphQLResolveInfo } from 'graphql'; | ||
import { AppSyncGraphQLExecutionContext } from '../../../utils/graphql-runner'; | ||
import { AmplifyAppSyncSimulatorAuthenticationType } from '../../../type-definition'; | ||
|
||
const stubInfo = {} as unknown; | ||
const mockInfo = stubInfo as GraphQLResolveInfo; | ||
|
||
describe('$util.authType', () => { | ||
it('should return API Key Authorization', () => { | ||
const executionContext: AppSyncGraphQLExecutionContext = { | ||
headers: { 'x-api-key': 'da-fake-key' }, | ||
requestAuthorizationMode: AmplifyAppSyncSimulatorAuthenticationType.API_KEY, | ||
appsyncErrors: [], | ||
}; | ||
|
||
const util = create(undefined, undefined, mockInfo, executionContext); | ||
|
||
expect(util.authType()).toEqual('API Key Authorization'); | ||
}); | ||
|
||
it('should return IAM Authorization', () => { | ||
const executionContext: AppSyncGraphQLExecutionContext = { | ||
headers: { 'x-api-key': 'da-fake-key' }, | ||
requestAuthorizationMode: AmplifyAppSyncSimulatorAuthenticationType.AWS_IAM, | ||
appsyncErrors: [], | ||
}; | ||
|
||
const util = create(undefined, undefined, mockInfo, executionContext); | ||
|
||
expect(util.authType()).toEqual('IAM Authorization'); | ||
}); | ||
|
||
it('should return Open ID Connect Authorization', () => { | ||
const executionContext: AppSyncGraphQLExecutionContext = { | ||
headers: { 'x-api-key': 'da-fake-key' }, | ||
requestAuthorizationMode: AmplifyAppSyncSimulatorAuthenticationType.OPENID_CONNECT, | ||
appsyncErrors: [], | ||
}; | ||
|
||
const util = create(undefined, undefined, mockInfo, executionContext); | ||
|
||
expect(util.authType()).toEqual('Open ID Connect Authorization'); | ||
}); | ||
|
||
it('should return User Pool Authorization', () => { | ||
const executionContext: AppSyncGraphQLExecutionContext = { | ||
headers: { 'x-api-key': 'da-fake-key' }, | ||
requestAuthorizationMode: AmplifyAppSyncSimulatorAuthenticationType.AMAZON_COGNITO_USER_POOLS, | ||
appsyncErrors: [], | ||
}; | ||
|
||
const util = create(undefined, undefined, mockInfo, executionContext); | ||
|
||
expect(util.authType()).toEqual('User Pool Authorization'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
packages/amplify-appsync-simulator/src/__tests__/velocity/util/list-utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
packages/amplify-appsync-simulator/src/__tests__/velocity/util/math.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
packages/amplify-appsync-simulator/src/__tests__/velocity/util/rds.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
packages/amplify-appsync-simulator/src/__tests__/velocity/util/str.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/amplify-appsync-simulator/src/velocity/util/auth-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { AmplifyAppSyncSimulatorAuthenticationType } from '../../type-definition'; | ||
|
||
export const authUtils = context => ({ | ||
authType() { | ||
if (context.requestAuthorizationMode === AmplifyAppSyncSimulatorAuthenticationType.API_KEY) { | ||
return 'API Key Authorization'; | ||
} else if (context.requestAuthorizationMode === AmplifyAppSyncSimulatorAuthenticationType.AWS_IAM) { | ||
return 'IAM Authorization'; | ||
} else if (context.requestAuthorizationMode === AmplifyAppSyncSimulatorAuthenticationType.AMAZON_COGNITO_USER_POOLS) { | ||
return 'User Pool Authorization'; | ||
} else if (context.requestAuthorizationMode === AmplifyAppSyncSimulatorAuthenticationType.OPENID_CONNECT) { | ||
return 'Open ID Connect Authorization'; | ||
} | ||
|
||
return 'API Key Authorization'; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters