Skip to content

Commit

Permalink
Small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joerger committed Dec 19, 2024
1 parent afb83d6 commit bf14661
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions web/packages/teleport/src/services/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,13 @@ const auth = {
.then(res => res.webauthn_response);
},

getAdminActionMfaResponse(allowReuse?: boolean) {
async getAdminActionMfaResponse(allowReuse?: boolean) {
return mfaContext.getAdminActionMfaResponse(allowReuse);
},

// TODO(Joerger): Delete in favor of getMfaChallengeResponseForAdminAction once /e is updated.
getWebauthnResponseForAdminAction(allowReuse?: boolean) {
return mfaContext.getAdminActionMfaResponse(allowReuse);
async getWebauthnResponseForAdminAction(allowReuse?: boolean) {
return auth.getAdminActionMfaResponse(allowReuse);
},
};

Expand Down
18 changes: 12 additions & 6 deletions web/packages/teleport/src/services/joinToken/joinToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import api from 'teleport/services/api';
import cfg from 'teleport/config';
import api from 'teleport/services/api';

import auth from '../auth/auth';

import JoinTokenService from './joinToken';

import type { JoinTokenRequest } from './types';

test('fetchJoinToken with an empty request properly sets defaults', () => {
test('fetchJoinToken with an empty request properly sets defaults', async () => {
const svc = new JoinTokenService();
jest.spyOn(api, 'post').mockResolvedValue(null);
jest.spyOn(auth, 'getAdminActionMfaResponse').mockResolvedValue(null);

// Test with all empty fields.
svc.fetchJoinToken({} as any);
await svc.fetchJoinToken({} as any);
expect(api.post).toHaveBeenCalledWith(
cfg.getJoinTokenUrl(),
{
Expand All @@ -37,21 +39,24 @@ test('fetchJoinToken with an empty request properly sets defaults', () => {
allow: [],
suggested_agent_matcher_labels: {},
},
null,
null
);
});

test('fetchJoinToken request fields are set as requested', () => {
test('fetchJoinToken request fields are set as requested', async () => {
const svc = new JoinTokenService();
jest.spyOn(api, 'post').mockResolvedValue(null);
jest.spyOn(auth, 'getAdminActionMfaResponse').mockResolvedValue(null);

const mock: JoinTokenRequest = {
roles: ['Node'],
rules: [{ awsAccountId: '1234', awsArn: 'xxxx' }],
method: 'iam',
suggestedAgentMatcherLabels: [{ name: 'env', value: 'dev' }],
};
svc.fetchJoinToken(mock);
await svc.fetchJoinToken(mock);

expect(api.post).toHaveBeenCalledWith(
cfg.getJoinTokenUrl(),
{
Expand All @@ -60,6 +65,7 @@ test('fetchJoinToken request fields are set as requested', () => {
allow: [{ aws_account: '1234', aws_arn: 'xxxx' }],
suggested_agent_matcher_labels: { env: ['dev'] },
},
null,
null
);
});

0 comments on commit bf14661

Please sign in to comment.