Skip to content

Commit

Permalink
Fix lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joerger committed Dec 10, 2024
1 parent 25df311 commit 91c848b
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 120 deletions.
5 changes: 1 addition & 4 deletions web/packages/teleport/src/Account/Account.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ import cfg from 'teleport/config';
import { createTeleportContext } from 'teleport/mocks/contexts';
import { PasswordState } from 'teleport/services/user';
import auth from 'teleport/services/auth/auth';
import MfaService, {
MfaDevice,
WebauthnAssertionResponse,
} from 'teleport/services/mfa';
import MfaService, { MfaDevice } from 'teleport/services/mfa';

const defaultAuthType = cfg.auth.second_factor;
const defaultPasswordless = cfg.auth.allowPasswordless;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { userEvent, UserEvent } from '@testing-library/user-event';
import auth, { MfaChallengeScope } from 'teleport/services/auth/auth';

import {
MFA_OPTION_SSO_DEFAULT,
MFA_OPTION_TOTP,
MFA_OPTION_WEBAUTHN,
MfaChallengeResponse,
Expand Down Expand Up @@ -90,15 +89,15 @@ describe('with passwordless reauthentication', () => {
async function reauthenticate() {
render(<TestWizard />);

const reauthenticateStep = await waitFor(() => {
return within(screen.getByTestId('reauthenticate-step'));
await waitFor(() => {
expect(screen.getByTestId('reauthenticate-step')).toBeInTheDocument();
});
expect(auth.getMfaChallenge).toHaveBeenCalledWith({
scope: MfaChallengeScope.CHANGE_PASSWORD,
});

await user.click(reauthenticateStep.getByText('Passkey'));
await user.click(reauthenticateStep.getByText('Next'));
await user.click(screen.getByText('Passkey'));
await user.click(screen.getByText('Next'));
expect(auth.getMfaChallenge).toHaveBeenCalledWith({
scope: MfaChallengeScope.CHANGE_PASSWORD,
userVerificationRequirement: 'required',
Expand Down Expand Up @@ -188,15 +187,15 @@ describe('with WebAuthn MFA reauthentication', () => {
async function reauthenticate() {
render(<TestWizard />);

const reauthenticateStep = await waitFor(() => {
return within(screen.getByTestId('reauthenticate-step'));
await waitFor(() => {
expect(screen.getByTestId('reauthenticate-step')).toBeInTheDocument();
});
expect(auth.getMfaChallenge).toHaveBeenCalledWith({
scope: MfaChallengeScope.CHANGE_PASSWORD,
});

await user.click(reauthenticateStep.getByText('Security Key'));
await user.click(reauthenticateStep.getByText('Next'));
await user.click(screen.getByText('Security Key'));
await user.click(screen.getByText('Next'));
expect(auth.getMfaChallengeResponse).toHaveBeenCalled();
}

Expand Down Expand Up @@ -293,11 +292,11 @@ describe('with OTP MFA reauthentication', () => {
async function reauthenticate() {
render(<TestWizard />);

const reauthenticateStep = await waitFor(() => {
return within(screen.getByTestId('reauthenticate-step'));
await waitFor(() => {
expect(screen.getByTestId('reauthenticate-step')).toBeInTheDocument();
});
await user.click(reauthenticateStep.getByText('Authenticator App'));
await user.click(reauthenticateStep.getByText('Next'));
await user.click(screen.getByText('Authenticator App'));
await user.click(screen.getByText('Next'));
}

it('changes password', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { useAsync } from 'shared/hooks/useAsync';

import Box from 'design/Box';

import Indicator from 'design/Indicator';

import { ChangePasswordReq } from 'teleport/services/auth';
import auth, { MfaChallengeScope } from 'teleport/services/auth/auth';
import {
Expand All @@ -43,7 +45,6 @@ import {
WebauthnAssertionResponse,
} from 'teleport/services/mfa';
import useReAuthenticate from 'teleport/components/ReAuthenticate/useReAuthenticate';
import Indicator from 'design/Indicator';

export interface ChangePasswordWizardProps {
hasPasswordless: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import Dialog from 'design/Dialog';

import { http, HttpResponse, delay } from 'msw';

import { Attempt } from 'shared/hooks/useAttemptNext';

import { createTeleportContext } from 'teleport/mocks/contexts';
import { ContextProvider } from 'teleport/index';

import cfg from 'teleport/config';

import {
DeviceType,
DeviceUsage,
MFA_OPTION_SSO_DEFAULT,
MFA_OPTION_TOTP,
Expand All @@ -41,7 +42,6 @@ import {
SaveDeviceStep,
} from './AddAuthDeviceWizard';
import { ReauthenticateStep } from './ReauthenticateStep';
import { Attempt } from 'shared/hooks/useAttemptNext';

export default {
title: 'teleport/Account/Manage Devices/Add Device Wizard',
Expand Down Expand Up @@ -177,12 +177,12 @@ const stepProps: AddAuthDeviceWizardStepProps = {
MFA_OPTION_TOTP,
MFA_OPTION_SSO_DEFAULT,
],
submitWithMfa: async (mfaType?: DeviceType, otpCode?: string) => {},
submitWithMfa: async () => {},

// Create props
mfaRegisterOptions: [MFA_OPTION_WEBAUTHN, MFA_OPTION_TOTP],
onDeviceCreated: (c: Credential) => {},
onNewMfaDeviceTypeChange: (d: DeviceType) => {},
onDeviceCreated: () => {},
onNewMfaDeviceTypeChange: () => {},

// Save props
credential: { id: 'cred-id', type: 'public-key' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { render, screen } from 'design/utils/testing';
import React from 'react';

import { waitFor, within } from '@testing-library/react';
import { waitFor } from '@testing-library/react';
import { userEvent, UserEvent } from '@testing-library/user-event';

import TeleportContext from 'teleport/teleportContext';
Expand Down Expand Up @@ -82,22 +82,18 @@ describe('flow without reauthentication', () => {
<TestWizard usage="passwordless" privilegeToken="privilege-token" />
);

const createStep = await waitFor(() => {
return within(screen.getByTestId('create-step'));
await waitFor(() => {
expect(screen.getByTestId('create-step')).toBeInTheDocument();
});
await user.click(
createStep.getByRole('button', { name: 'Create a passkey' })
);
await user.click(screen.getByRole('button', { name: 'Create a passkey' }));
expect(auth.createNewWebAuthnDevice).toHaveBeenCalledWith({
tokenId: 'privilege-token',
deviceUsage: 'passwordless',
});

const saveStep = within(screen.getByTestId('save-step'));
await user.type(saveStep.getByLabelText('Passkey Nickname'), 'new-passkey');
await user.click(
saveStep.getByRole('button', { name: 'Save the Passkey' })
);
expect(screen.getByTestId('save-step')).toBeInTheDocument();
await user.type(screen.getByLabelText('Passkey Nickname'), 'new-passkey');
await user.click(screen.getByRole('button', { name: 'Save the Passkey' }));
expect(ctx.mfaService.saveNewWebAuthnDevice).toHaveBeenCalledWith({
credential: dummyCredential,
addRequest: {
Expand All @@ -112,22 +108,22 @@ describe('flow without reauthentication', () => {
test('adds a WebAuthn MFA', async () => {
render(<TestWizard usage="mfa" privilegeToken="privilege-token" />);

const createStep = await waitFor(() => {
return within(screen.getByTestId('create-step'));
await waitFor(() => {
expect(screen.getByTestId('create-step')).toBeInTheDocument();
});
await user.click(createStep.getByLabelText('Security Key'));
await user.click(screen.getByLabelText('Security Key'));
await user.click(
createStep.getByRole('button', { name: 'Create an MFA method' })
screen.getByRole('button', { name: 'Create an MFA method' })
);
expect(auth.createNewWebAuthnDevice).toHaveBeenCalledWith({
tokenId: 'privilege-token',
deviceUsage: 'mfa',
});

const saveStep = within(screen.getByTestId('save-step'));
await user.type(saveStep.getByLabelText('MFA Method Name'), 'new-mfa');
expect(screen.getByTestId('save-step')).toBeInTheDocument();
await user.type(screen.getByLabelText('MFA Method Name'), 'new-mfa');
await user.click(
saveStep.getByRole('button', { name: 'Save the MFA method' })
screen.getByRole('button', { name: 'Save the MFA method' })
);
expect(ctx.mfaService.saveNewWebAuthnDevice).toHaveBeenCalledWith({
credential: dummyCredential,
Expand All @@ -143,24 +139,24 @@ describe('flow without reauthentication', () => {
test('adds an authenticator app', async () => {
render(<TestWizard usage="mfa" privilegeToken="privilege-token" />);

const createStep = await waitFor(() => {
return within(screen.getByTestId('create-step'));
await waitFor(() => {
expect(screen.getByTestId('create-step')).toBeInTheDocument();
});

await user.click(createStep.getByLabelText('Authenticator App'));
expect(createStep.getByRole('img')).toHaveAttribute(
await user.click(screen.getByLabelText('Authenticator App'));
expect(screen.getByRole('img')).toHaveAttribute(
'src',
'data:image/png;base64,dummy-qr-code'
);
await user.click(
createStep.getByRole('button', { name: 'Create an MFA method' })
screen.getByRole('button', { name: 'Create an MFA method' })
);

const saveStep = within(screen.getByTestId('save-step'));
await user.type(saveStep.getByLabelText('MFA Method Name'), 'new-mfa');
await user.type(saveStep.getByLabelText(/Authenticator Code/), '345678');
expect(screen.getByTestId('save-step')).toBeInTheDocument();
await user.type(screen.getByLabelText('MFA Method Name'), 'new-mfa');
await user.type(screen.getByLabelText(/Authenticator Code/), '345678');
await user.click(
saveStep.getByRole('button', { name: 'Save the MFA method' })
screen.getByRole('button', { name: 'Save the MFA method' })
);
expect(ctx.mfaService.addNewTotpDevice).toHaveBeenCalledWith({
tokenId: 'privilege-token',
Expand All @@ -186,28 +182,24 @@ describe('flow with reauthentication', () => {
test('adds a passkey with WebAuthn reauthentication', async () => {
render(<TestWizard usage="passwordless" />);

const reauthenticateStep = await waitFor(() => {
return within(screen.getByTestId('reauthenticate-step'));
await waitFor(() => {
expect(screen.getByTestId('reauthenticate-step')).toBeInTheDocument();
});

await user.click(reauthenticateStep.getByText('Verify my identity'));
await user.click(screen.getByText('Verify my identity'));

const createStep = await waitFor(() => {
return within(screen.getByTestId('create-step'));
await waitFor(() => {
expect(screen.getByTestId('create-step')).toBeInTheDocument();
});
await user.click(
createStep.getByRole('button', { name: 'Create a passkey' })
);
await user.click(screen.getByRole('button', { name: 'Create a passkey' }));
expect(auth.createNewWebAuthnDevice).toHaveBeenCalledWith({
tokenId: 'privilege-token',
deviceUsage: 'passwordless',
});

const saveStep = within(screen.getByTestId('save-step'));
await user.type(saveStep.getByLabelText('Passkey Nickname'), 'new-passkey');
await user.click(
saveStep.getByRole('button', { name: 'Save the Passkey' })
);
expect(screen.getByTestId('save-step')).toBeInTheDocument();
await user.type(screen.getByLabelText('Passkey Nickname'), 'new-passkey');
await user.click(screen.getByRole('button', { name: 'Save the Passkey' }));
expect(ctx.mfaService.saveNewWebAuthnDevice).toHaveBeenCalledWith({
credential: dummyCredential,
addRequest: {
Expand All @@ -222,33 +214,26 @@ describe('flow with reauthentication', () => {
test('adds a passkey with OTP reauthentication', async () => {
render(<TestWizard usage="passwordless" />);

const reauthenticateStep = await waitFor(() => {
return within(screen.getByTestId('reauthenticate-step'));
await waitFor(() => {
expect(screen.getByTestId('reauthenticate-step')).toBeInTheDocument();
});

await user.click(reauthenticateStep.getByText('Authenticator App'));
await user.type(
reauthenticateStep.getByLabelText('Authenticator Code'),
'654987'
);
await user.click(reauthenticateStep.getByText('Verify my identity'));
await user.click(screen.getByText('Authenticator App'));
await user.type(screen.getByLabelText('Authenticator Code'), '654987');
await user.click(screen.getByText('Verify my identity'));

const createStep = await waitFor(() => {
return within(screen.getByTestId('create-step'));
await waitFor(() => {
expect(screen.getByTestId('create-step')).toBeInTheDocument();
});
await user.click(
createStep.getByRole('button', { name: 'Create a passkey' })
);
await user.click(screen.getByRole('button', { name: 'Create a passkey' }));
expect(auth.createNewWebAuthnDevice).toHaveBeenCalledWith({
tokenId: 'privilege-token',
deviceUsage: 'passwordless',
});

const saveStep = within(screen.getByTestId('save-step'));
await user.type(saveStep.getByLabelText('Passkey Nickname'), 'new-passkey');
await user.click(
saveStep.getByRole('button', { name: 'Save the Passkey' })
);
expect(screen.getByTestId('save-step')).toBeInTheDocument();
await user.type(screen.getByLabelText('Passkey Nickname'), 'new-passkey');
await user.click(screen.getByRole('button', { name: 'Save the Passkey' }));
expect(ctx.mfaService.saveNewWebAuthnDevice).toHaveBeenCalledWith({
credential: dummyCredential,
addRequest: {
Expand All @@ -263,15 +248,11 @@ describe('flow with reauthentication', () => {
test('shows reauthentication options', async () => {
render(<TestWizard usage="mfa" />);

const reauthenticateStep = await waitFor(() => {
return within(screen.getByTestId('reauthenticate-step'));
await waitFor(() => {
expect(screen.getByTestId('reauthenticate-step')).toBeInTheDocument();
});

expect(
reauthenticateStep.queryByLabelText(/passkey or security key/i)
).toBeVisible();
expect(
reauthenticateStep.queryByLabelText(/authenticator app/i)
).toBeVisible();
expect(screen.queryByLabelText(/passkey or security key/i)).toBeVisible();
expect(screen.queryByLabelText(/authenticator app/i)).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import React from 'react';

import Dialog from 'design/Dialog';

import { Attempt } from 'shared/hooks/useAttemptNext';

import { createTeleportContext } from 'teleport/mocks/contexts';
import { ContextProvider } from 'teleport/index';

import {
DeviceType,
MFA_OPTION_SSO_DEFAULT,
MFA_OPTION_TOTP,
MFA_OPTION_WEBAUTHN,
Expand All @@ -36,7 +37,6 @@ import {
DeleteDeviceStep,
} from './DeleteAuthDeviceWizard';
import { ReauthenticateStep } from './ReauthenticateStep';
import { Attempt } from 'shared/hooks/useAttemptNext';

export default {
title: 'teleport/Account/Manage Devices/Delete Device Wizard',
Expand Down Expand Up @@ -121,5 +121,5 @@ const stepProps: DeleteAuthDeviceWizardStepProps = {
MFA_OPTION_TOTP,
MFA_OPTION_SSO_DEFAULT,
],
submitWithMfa: async (mfaType?: DeviceType, otpCode?: string) => {},
submitWithMfa: async () => {},
};
Loading

0 comments on commit 91c848b

Please sign in to comment.