-
Notifications
You must be signed in to change notification settings - Fork 163
implemented kubernetes auth #155
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,12 @@ inputs: | |
| githubToken: | ||
| description: 'The Github Token to be used to authenticate with Vault' | ||
| required: false | ||
| roleName: | ||
| description: "The role name for the kubernetes authentification" | ||
|
jogueber marked this conversation as resolved.
|
||
| required: false | ||
| tokenPath: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably have a default
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gonna do that :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jojo19893 Are you still planning on making this change? I can, to get this moving again
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Poke 😄 |
||
| description: "The path to the kubernetes service account secret, the action reads the content of this file on the runner" | ||
|
jogueber marked this conversation as resolved.
Outdated
|
||
| required: false | ||
| authPayload: | ||
| description: 'The JSON payload to be sent to Vault when using a custom authentication method.' | ||
| required: false | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| jest.mock('got'); | ||
| jest.mock('@actions/core'); | ||
| jest.mock('@actions/core/lib/command'); | ||
| jest.mock("fs") | ||
|
|
||
| const core = require('@actions/core'); | ||
| const got = require('got'); | ||
| const fs = require("fs") | ||
| const { when } = require('jest-when'); | ||
|
|
||
|
|
||
| const { | ||
| retrieveToken | ||
| } = require('./auth'); | ||
|
|
||
|
|
||
| function mockInput(name, key) { | ||
| when(core.getInput) | ||
| .calledWith(name) | ||
| .mockReturnValueOnce(key); | ||
| } | ||
|
|
||
| function mockApiResponse() { | ||
| const response = { body: { auth: { client_token: testToken, renewable: true, policies: [], accessor: "accessor" } } } | ||
| got.post = jest.fn() | ||
| got.post.mockReturnValue(response) | ||
| } | ||
| const testToken = "testoken"; | ||
|
|
||
| describe("test retrival for token", () => { | ||
|
|
||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
|
||
| it("test retrival with approle", async () => { | ||
| const method = 'approle' | ||
| mockApiResponse() | ||
| const testRoleId = "testRoleId" | ||
| const testSecretId = "testSecretId" | ||
| mockInput("roleId", testRoleId) | ||
| mockInput("secretId", testSecretId) | ||
| const token = await retrieveToken(method, got) | ||
| expect(token).toEqual(testToken) | ||
| const payload = got.post.mock.calls[0][1].json | ||
| expect(payload).toEqual({ role_id: testRoleId, secret_id: testSecretId }) | ||
| const url = got.post.mock.calls[0][0] | ||
| expect(url).toContain('approle') | ||
| }) | ||
|
|
||
| it("test retrival with github token", async () => { | ||
| const method = 'github' | ||
| mockApiResponse() | ||
| const githubToken = "githubtoken" | ||
| mockInput("githubToken", githubToken) | ||
| const token = await retrieveToken(method, got) | ||
| expect(token).toEqual(testToken) | ||
| const payload = got.post.mock.calls[0][1].json | ||
| expect(payload).toEqual({ token: githubToken }) | ||
| const url = got.post.mock.calls[0][0] | ||
| expect(url).toContain('github') | ||
| }) | ||
|
|
||
| it("test retrival with kubernetes", async () => { | ||
| const method = 'kubernetes' | ||
| const jwtToken = "someJwtToken" | ||
| const testRoleName = "testRoleName" | ||
| const testTokenPath = "testTokenPath" | ||
| mockApiResponse() | ||
| mockInput("tokenPath", testTokenPath) | ||
| mockInput("roleName", testRoleName) | ||
| fs.readFileSync = jest.fn() | ||
| fs.readFileSync.mockReturnValueOnce(jwtToken) | ||
| const token = await retrieveToken(method, got) | ||
| expect(token).toEqual(testToken) | ||
| const payload = got.post.mock.calls[0][1].json | ||
| expect(payload).toEqual({ jwt: jwtToken, role: testRoleName }) | ||
| const url = got.post.mock.calls[0][0] | ||
| expect(url).toContain('kubernetes') | ||
| }) | ||
|
|
||
| }) |
Uh oh!
There was an error while loading. Please reload this page.