-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branches 'rorticus-set-fix' and 'createUserPoolClient-regression'
- Loading branch information
Showing
19 changed files
with
179 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
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
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,70 @@ | ||
import { advanceTo } from "jest-date-mock"; | ||
import { ResourceNotFoundError } from "../errors"; | ||
import { CognitoClient, UserPoolClient } from "../services"; | ||
import { AppClient } from "../services/appClient"; | ||
import { | ||
DescribeUserPoolClient, | ||
DescribeUserPoolClientTarget, | ||
} from "./describeUserPoolClient"; | ||
|
||
describe("DescribeUserPoolClient target", () => { | ||
let describeUserPoolClient: DescribeUserPoolClientTarget; | ||
let mockCognitoClient: jest.Mocked<CognitoClient>; | ||
let mockUserPoolClient: jest.Mocked<UserPoolClient>; | ||
let now: Date; | ||
|
||
beforeEach(() => { | ||
now = new Date(2020, 1, 2, 3, 4, 5); | ||
advanceTo(now); | ||
|
||
mockUserPoolClient = { | ||
config: { | ||
Id: "test", | ||
}, | ||
createAppClient: jest.fn(), | ||
getUserByUsername: jest.fn(), | ||
listUsers: jest.fn(), | ||
saveUser: jest.fn(), | ||
}; | ||
mockCognitoClient = { | ||
getAppClient: jest.fn(), | ||
getUserPool: jest.fn().mockResolvedValue(mockUserPoolClient), | ||
getUserPoolForClientId: jest.fn().mockResolvedValue(mockUserPoolClient), | ||
}; | ||
|
||
describeUserPoolClient = DescribeUserPoolClient({ | ||
cognitoClient: mockCognitoClient, | ||
}); | ||
}); | ||
|
||
it("returns an existing app client", async () => { | ||
const existingAppClient: AppClient = { | ||
RefreshTokenValidity: 30, | ||
AllowedOAuthFlowsUserPoolClient: false, | ||
LastModifiedDate: new Date().getTime(), | ||
CreationDate: new Date().getTime(), | ||
UserPoolId: "userPoolId", | ||
ClientId: "abc", | ||
ClientName: "clientName", | ||
}; | ||
mockCognitoClient.getAppClient.mockResolvedValue(existingAppClient); | ||
|
||
const result = await describeUserPoolClient({ | ||
ClientId: "abc", | ||
UserPoolId: "userPoolId", | ||
}); | ||
|
||
expect(result).toEqual({ UserPoolClient: existingAppClient }); | ||
}); | ||
|
||
it("throws resource not found for an invalid app client", async () => { | ||
mockCognitoClient.getAppClient.mockResolvedValue(null); | ||
|
||
await expect( | ||
describeUserPoolClient({ | ||
ClientId: "abc", | ||
UserPoolId: "userPoolId", | ||
}) | ||
).rejects.toEqual(new ResourceNotFoundError()); | ||
}); | ||
}); |
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,72 @@ | ||
import { ResourceNotFoundError } from "../errors"; | ||
import { Services } from "../services"; | ||
import { UserAttribute } from "../services/userPoolClient"; | ||
|
||
interface Input { | ||
ClientId: string; | ||
UserPoolId: string; | ||
} | ||
|
||
export interface DynamoDBUserRecord { | ||
Username: string; | ||
UserCreateDate: number; | ||
UserLastModifiedDate: number; | ||
Enabled: boolean; | ||
UserStatus: "CONFIRMED" | "UNCONFIRMED" | "RESET_REQUIRED"; | ||
Attributes: readonly UserAttribute[]; | ||
} | ||
|
||
interface Output { | ||
UserPoolClient: { | ||
AccessTokenValidity?: number; | ||
AllowedOAuthFlows?: ("code" | "implicit" | "client_credentials")[]; | ||
AllowedOAuthFlowsUserPoolClient?: boolean; | ||
AllowedOAuthScopes?: string[]; | ||
AnalyticsConfiguration?: { | ||
ApplicationArn?: string; | ||
ApplicationId?: string; | ||
ExternalId?: string; | ||
RoleArn?: string; | ||
UserDataShared?: boolean; | ||
}; | ||
CallbackURLs?: string[]; | ||
ClientId?: string; | ||
ClientName?: string; | ||
ClientSecret?: string; | ||
CreationDate?: number; | ||
DefaultRedirectURI?: string; | ||
EnableTokenRevocation?: boolean; | ||
ExplicitAuthFlows?: string[]; | ||
IdTokenValidity?: number; | ||
LastModifiedDate?: number; | ||
LogoutURLs?: string[]; | ||
PreventUserExistenceErrors?: "LEGACY" | "ENABLED"; | ||
ReadAttributes?: string[]; | ||
RefreshTokenValidity?: number; | ||
SupportedIdentityProviders?: string[]; | ||
TokenValidityUnits?: { | ||
AccessToken?: "seconds" | "minutes" | "hours" | "days"; | ||
IdToken?: "seconds" | "minutes" | "hours" | "days"; | ||
RefreshToken?: "seconds" | "minutes" | "hours" | "days"; | ||
}; | ||
UserPoolId?: string; | ||
WriteAttributes?: string[]; | ||
}; | ||
} | ||
|
||
export type DescribeUserPoolClientTarget = (body: Input) => Promise<Output>; | ||
|
||
export const DescribeUserPoolClient = ({ | ||
cognitoClient, | ||
}: Pick<Services, "cognitoClient">): DescribeUserPoolClientTarget => async ( | ||
body | ||
) => { | ||
const client = await cognitoClient.getAppClient(body.ClientId); | ||
if (client?.UserPoolId !== body.UserPoolId) { | ||
throw new ResourceNotFoundError(); | ||
} | ||
|
||
return { | ||
UserPoolClient: client, | ||
}; | ||
}; |
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
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
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
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