Skip to content

chore(runners): Add unit test for line break in app key #1397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions modules/runners/lambdas/runners/src/scale-runners/gh-auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ describe('Test createGithubAppAuth', () => {
process.env.ENVIRONMENT = ENVIRONMENT;
});

test('Creates auth object with line breaks in SSH key.', async () => {
// Arrange
const authOptions = {
appId: parseInt(GITHUB_APP_ID),
privateKey: `${decryptedValue}
${decryptedValue}`,
installationId,
};

const b64PrivateKeyWithLineBreaks = Buffer.from(decryptedValue + '\n' + decryptedValue, 'binary').toString(
'base64',
);
mockedGet.mockResolvedValueOnce(GITHUB_APP_ID).mockResolvedValueOnce(b64PrivateKeyWithLineBreaks);

const mockedAuth = jest.fn();
mockedAuth.mockResolvedValue({ token });
mockedCreatAppAuth.mockImplementation(() => {
return mockedAuth;
});

// Act
await createGithubAppAuth(installationId);

// Assert
expect(mockedCreatAppAuth).toBeCalledTimes(1);
expect(mockedCreatAppAuth).toBeCalledWith(authOptions);
});

test('Creates auth object for public GitHub', async () => {
// Arrange
const authOptions = {
Expand Down