Fix linting errors after #13392
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -109,8 +109,13 @@ describe('FirestoreKeyStore', () => {
|
||||
const keyStore = await FirestoreKeyStore.create();
|
||||
await keyStore.addKey(key);
|
||||
|
||||
expect(setTimeout).toBeCalledWith(expect.any(Function), DEFAULT_TIMEOUT_MS);
|
||||
expect(firestoreMock.collection).toBeCalledWith(DEFAULT_DOCUMENT_PATH);
|
||||
expect(setTimeout).toHaveBeenCalledWith(
|
||||
expect.any(Function),
|
||||
DEFAULT_TIMEOUT_MS,
|
||||
);
|
||||
expect(firestoreMock.collection).toHaveBeenCalledWith(
|
||||
DEFAULT_DOCUMENT_PATH,
|
||||
);
|
||||
});
|
||||
|
||||
it('can handle a timeout', async () => {
|
||||
@@ -135,9 +140,9 @@ describe('FirestoreKeyStore', () => {
|
||||
const keyStore = await FirestoreKeyStore.create(firestoreSettings);
|
||||
await keyStore.addKey(key);
|
||||
|
||||
expect(setTimeout).toBeCalledTimes(1);
|
||||
expect(firestoreMock.collection).toBeCalledWith(path);
|
||||
expect(firestoreMock.doc).toBeCalledWith(key.kid);
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
expect(firestoreMock.collection).toHaveBeenCalledWith(path);
|
||||
expect(firestoreMock.doc).toHaveBeenCalledWith(key.kid);
|
||||
expect(firestoreMock.set).toHaveBeenCalledWith({
|
||||
kid: key.kid,
|
||||
key: JSON.stringify(key),
|
||||
@@ -148,32 +153,32 @@ describe('FirestoreKeyStore', () => {
|
||||
const keyStore = await FirestoreKeyStore.create(firestoreSettings);
|
||||
await keyStore.removeKeys(['123']);
|
||||
|
||||
expect(setTimeout).toBeCalledTimes(1);
|
||||
expect(firestoreMock.collection).toBeCalledWith(path);
|
||||
expect(firestoreMock.doc).toBeCalledWith('123');
|
||||
expect(firestoreMock.delete).toBeCalledTimes(1);
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
expect(firestoreMock.collection).toHaveBeenCalledWith(path);
|
||||
expect(firestoreMock.doc).toHaveBeenCalledWith('123');
|
||||
expect(firestoreMock.delete).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('can delete a multiple keys', async () => {
|
||||
const keyStore = await FirestoreKeyStore.create(firestoreSettings);
|
||||
await keyStore.removeKeys(['123', '456']);
|
||||
|
||||
expect(setTimeout).toBeCalledTimes(2);
|
||||
expect(firestoreMock.collection).toBeCalledWith(path);
|
||||
expect(firestoreMock.doc).toBeCalledWith('123');
|
||||
expect(firestoreMock.doc).toBeCalledWith('456');
|
||||
expect(firestoreMock.delete).toBeCalledTimes(2);
|
||||
expect(setTimeout).toHaveBeenCalledTimes(2);
|
||||
expect(firestoreMock.collection).toHaveBeenCalledWith(path);
|
||||
expect(firestoreMock.doc).toHaveBeenCalledWith('123');
|
||||
expect(firestoreMock.doc).toHaveBeenCalledWith('456');
|
||||
expect(firestoreMock.delete).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('can list keys', async () => {
|
||||
const keyStore = await FirestoreKeyStore.create(firestoreSettings);
|
||||
const items = await keyStore.listKeys();
|
||||
|
||||
expect(setTimeout).toBeCalledTimes(1);
|
||||
expect(firestoreMock.collection).toBeCalledWith(path);
|
||||
expect(firestoreMock.get).toBeCalledTimes(1);
|
||||
expect(data).toBeCalledTimes(1);
|
||||
expect(toDate).toBeCalledTimes(1);
|
||||
expect(setTimeout).toHaveBeenCalledTimes(1);
|
||||
expect(firestoreMock.collection).toHaveBeenCalledWith(path);
|
||||
expect(firestoreMock.get).toHaveBeenCalledTimes(1);
|
||||
expect(data).toHaveBeenCalledTimes(1);
|
||||
expect(toDate).toHaveBeenCalledTimes(1);
|
||||
expect(items).toMatchObject({
|
||||
items: [{ key: 'data', createdAt: 'date' }],
|
||||
});
|
||||
|
||||
@@ -128,7 +128,7 @@ describe('TokenFactory', () => {
|
||||
return factory.issueToken({
|
||||
claims: { sub: 'UserId' },
|
||||
});
|
||||
}).rejects.toThrowError();
|
||||
}).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('should throw error on empty algorithm string', async () => {
|
||||
@@ -145,7 +145,7 @@ describe('TokenFactory', () => {
|
||||
return factory.issueToken({
|
||||
claims: { sub: 'UserId' },
|
||||
});
|
||||
}).rejects.toThrowError();
|
||||
}).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('should defaults to ES256 when no algorithm string is supplied', async () => {
|
||||
|
||||
@@ -62,9 +62,11 @@ describe('oauth helpers', () => {
|
||||
const encoded = safelyEncodeURIComponent(JSON.stringify(data));
|
||||
|
||||
postMessageResponse(mockResponse, appOrigin, data);
|
||||
expect(mockResponse.setHeader).toBeCalledTimes(3);
|
||||
expect(mockResponse.end).toBeCalledTimes(1);
|
||||
expect(mockResponse.end).toBeCalledWith(expect.stringContaining(encoded));
|
||||
expect(mockResponse.setHeader).toHaveBeenCalledTimes(3);
|
||||
expect(mockResponse.end).toHaveBeenCalledTimes(1);
|
||||
expect(mockResponse.end).toHaveBeenCalledWith(
|
||||
expect.stringContaining(encoded),
|
||||
);
|
||||
});
|
||||
|
||||
it('should post a message back with payload error', () => {
|
||||
@@ -80,9 +82,11 @@ describe('oauth helpers', () => {
|
||||
const encoded = safelyEncodeURIComponent(JSON.stringify(data));
|
||||
|
||||
postMessageResponse(mockResponse, appOrigin, data);
|
||||
expect(mockResponse.setHeader).toBeCalledTimes(3);
|
||||
expect(mockResponse.end).toBeCalledTimes(1);
|
||||
expect(mockResponse.end).toBeCalledWith(expect.stringContaining(encoded));
|
||||
expect(mockResponse.setHeader).toHaveBeenCalledTimes(3);
|
||||
expect(mockResponse.end).toHaveBeenCalledTimes(1);
|
||||
expect(mockResponse.end).toHaveBeenCalledWith(
|
||||
expect.stringContaining(encoded),
|
||||
);
|
||||
});
|
||||
|
||||
it('should call postMessage twice but only one of them with target *', () => {
|
||||
@@ -166,9 +170,9 @@ describe('oauth helpers', () => {
|
||||
};
|
||||
|
||||
postMessageResponse(mockResponse, appOrigin, data);
|
||||
expect(mockResponse.setHeader).toBeCalledTimes(3);
|
||||
expect(mockResponse.end).toBeCalledTimes(1);
|
||||
expect(mockResponse.end).toBeCalledWith(
|
||||
expect(mockResponse.setHeader).toHaveBeenCalledTimes(3);
|
||||
expect(mockResponse.end).toHaveBeenCalledTimes(1);
|
||||
expect(mockResponse.end).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Adam%20l%27H%C3%B4pital'),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -92,8 +92,8 @@ describe('OAuthAdapter', () => {
|
||||
|
||||
await oauthProvider.start(mockRequest, mockResponse);
|
||||
// nonce cookie checks
|
||||
expect(mockResponse.cookie).toBeCalledTimes(1);
|
||||
expect(mockResponse.cookie).toBeCalledWith(
|
||||
expect(mockResponse.cookie).toHaveBeenCalledTimes(1);
|
||||
expect(mockResponse.cookie).toHaveBeenCalledWith(
|
||||
`${oAuthProviderOptions.providerId}-nonce`,
|
||||
expect.any(String),
|
||||
expect.objectContaining({ maxAge: TEN_MINUTES_MS }),
|
||||
@@ -323,8 +323,8 @@ describe('OAuthAdapter', () => {
|
||||
|
||||
await oauthProvider.start(mockRequest, mockResponse);
|
||||
|
||||
expect(mockResponse.cookie).toBeCalledTimes(1);
|
||||
expect(mockResponse.cookie).toBeCalledWith(
|
||||
expect(mockResponse.cookie).toHaveBeenCalledTimes(1);
|
||||
expect(mockResponse.cookie).toHaveBeenCalledWith(
|
||||
`${oAuthProviderOptions.providerId}-nonce`,
|
||||
expect.any(String),
|
||||
expect.objectContaining({
|
||||
|
||||
@@ -64,7 +64,7 @@ describe('OAuthProvider Utils', () => {
|
||||
} as unknown as express.Request;
|
||||
expect(() => {
|
||||
verifyNonce(mockRequest, 'providera');
|
||||
}).toThrowError('Auth response is missing cookie nonce');
|
||||
}).toThrow('Auth response is missing cookie nonce');
|
||||
});
|
||||
|
||||
it('should throw error if state nonce missing', () => {
|
||||
@@ -76,7 +76,7 @@ describe('OAuthProvider Utils', () => {
|
||||
} as unknown as express.Request;
|
||||
expect(() => {
|
||||
verifyNonce(mockRequest, 'providera');
|
||||
}).toThrowError('Invalid state passed via request');
|
||||
}).toThrow('Invalid state passed via request');
|
||||
});
|
||||
|
||||
it('should throw error if nonce mismatch', () => {
|
||||
@@ -91,7 +91,7 @@ describe('OAuthProvider Utils', () => {
|
||||
} as unknown as express.Request;
|
||||
expect(() => {
|
||||
verifyNonce(mockRequest, 'providera');
|
||||
}).toThrowError('Invalid nonce');
|
||||
}).toThrow('Invalid nonce');
|
||||
});
|
||||
|
||||
it('should not throw any error if nonce matches', () => {
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('PassportStrategyHelper', () => {
|
||||
mockStrategy,
|
||||
{},
|
||||
);
|
||||
expect(spyAuthenticate).toBeCalledTimes(1);
|
||||
expect(spyAuthenticate).toHaveBeenCalledTimes(1);
|
||||
await expect(redirectStrategyPromise).resolves.toStrictEqual(
|
||||
expect.objectContaining({ url: 'a', status: 302 }),
|
||||
);
|
||||
@@ -84,7 +84,7 @@ describe('PassportStrategyHelper', () => {
|
||||
mockRequest,
|
||||
mockStrategy,
|
||||
);
|
||||
expect(spyAuthenticate).toBeCalledTimes(1);
|
||||
expect(spyAuthenticate).toHaveBeenCalledTimes(1);
|
||||
await expect(frameHandlerStrategyPromise).resolves.toStrictEqual(
|
||||
expect.objectContaining({
|
||||
result: { accessToken: 'ACCESS_TOKEN' },
|
||||
@@ -100,7 +100,7 @@ describe('PassportStrategyHelper', () => {
|
||||
mockRequest,
|
||||
mockStrategy,
|
||||
);
|
||||
expect(spyAuthenticate).toBeCalledTimes(1);
|
||||
expect(spyAuthenticate).toHaveBeenCalledTimes(1);
|
||||
await expect(frameHandlerStrategyPromise).rejects.toThrow(
|
||||
'Authentication failed, MyCustomAuth error - Custom message',
|
||||
);
|
||||
@@ -113,7 +113,7 @@ describe('PassportStrategyHelper', () => {
|
||||
mockRequest,
|
||||
mockStrategy,
|
||||
);
|
||||
expect(spyAuthenticate).toBeCalledTimes(1);
|
||||
expect(spyAuthenticate).toHaveBeenCalledTimes(1);
|
||||
await expect(frameHandlerStrategyPromise).rejects.toThrow(
|
||||
'Unexpected redirect',
|
||||
);
|
||||
@@ -126,7 +126,7 @@ describe('PassportStrategyHelper', () => {
|
||||
mockRequest,
|
||||
mockStrategy,
|
||||
);
|
||||
expect(spyAuthenticate).toBeCalledTimes(1);
|
||||
expect(spyAuthenticate).toHaveBeenCalledTimes(1);
|
||||
await expect(frameHandlerStrategyPromise).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -233,7 +233,7 @@ describe('CloudflareAccessAuthProvider', () => {
|
||||
mockFetch.mockReturnValue(Promise.reject());
|
||||
await expect(
|
||||
provider.refresh(mockRequestWithJwtCookie, mockResponse),
|
||||
).rejects.toThrowError();
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ describe('helpers', () => {
|
||||
'a',
|
||||
mockClient as unknown as OAuth2Client,
|
||||
);
|
||||
await expect(validator(validJwt)).rejects.toThrowError(TypeError);
|
||||
await expect(validator(validJwt)).rejects.toThrow(TypeError);
|
||||
});
|
||||
|
||||
it('rejects empty payload', async () => {
|
||||
|
||||
@@ -122,7 +122,7 @@ describe('Oauth2ProxyAuthProvider', () => {
|
||||
|
||||
await provider.refresh(mockRequest, mockResponse);
|
||||
|
||||
expect(mockRequest.header).toBeCalledWith(OAUTH2_PROXY_JWT_HEADER);
|
||||
expect(mockRequest.header).toHaveBeenCalledWith(OAUTH2_PROXY_JWT_HEADER);
|
||||
expect(mockJwtDecode).toHaveBeenCalledWith('token');
|
||||
expect(mockResponse.json).toHaveBeenCalled();
|
||||
});
|
||||
@@ -197,7 +197,7 @@ describe('Oauth2ProxyAuthProvider', () => {
|
||||
} as any);
|
||||
await handler.refresh!(mockRequest, mockResponse);
|
||||
|
||||
expect(mockRequest.header).toBeCalledWith(OAUTH2_PROXY_JWT_HEADER);
|
||||
expect(mockRequest.header).toHaveBeenCalledWith(OAUTH2_PROXY_JWT_HEADER);
|
||||
expect(mockJwtDecode).toHaveBeenCalledWith('token');
|
||||
expect(mockResponse.json).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -83,7 +83,7 @@ describe('OidcAuthProvider', () => {
|
||||
};
|
||||
};
|
||||
// Assert that the expected request to the metadaurl was made.
|
||||
expect(handler).toBeCalledTimes(1);
|
||||
expect(handler).toHaveBeenCalledTimes(1);
|
||||
const { _client, _issuer } = strategy;
|
||||
expect(_client.client_id).toBe(clientMetadata.clientId);
|
||||
expect(_issuer.token_endpoint).toBe(issuerMetadata.token_endpoint);
|
||||
@@ -183,6 +183,6 @@ describe('OidcAuthProvider', () => {
|
||||
// Cast provider as any here to be able to inspect private members
|
||||
await (provider as any).handlers.get('testEnv').handlers.implementation;
|
||||
// Assert that the expected request to the metadaurl was made.
|
||||
expect(handler).toBeCalledTimes(1);
|
||||
expect(handler).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user