-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SSO option during PerSessionMFA in the web (#47876)
* Move SSOType * Add channelId and device to SSOChallenge * Add SSO option to AuthDialog * Remove autofocus * Update useEffect * Remove useEffect for broadcastChannel * Update authn dialog via UX team feedback * Review feedback
- Loading branch information
Showing
13 changed files
with
359 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
web/packages/teleport/src/components/AuthnDialog/AuthnDialog.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen, fireEvent } from 'design/utils/testing'; | ||
|
||
import { makeDefaultMfaState, MfaState } from 'teleport/lib/useMfa'; | ||
import { SSOChallenge } from 'teleport/services/auth'; | ||
|
||
import AuthnDialog from './AuthnDialog'; | ||
|
||
const mockSsoChallenge: SSOChallenge = { | ||
redirectUrl: 'url', | ||
requestId: '123', | ||
device: { | ||
displayName: 'Okta', | ||
connectorId: '123', | ||
connectorType: 'saml', | ||
}, | ||
channelId: '123', | ||
}; | ||
|
||
function makeMockState(partial: Partial<MfaState>): MfaState { | ||
const mfa = makeDefaultMfaState(); | ||
return { | ||
...mfa, | ||
...partial, | ||
}; | ||
} | ||
|
||
describe('AuthnDialog', () => { | ||
const mockOnCancel = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('renders the dialog with basic content', () => { | ||
const mfa = makeMockState({ ssoChallenge: mockSsoChallenge }); | ||
render(<AuthnDialog mfa={mfa} onCancel={mockOnCancel} />); | ||
|
||
expect( | ||
screen.getByText('Re-authenticate in the Browser') | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByText( | ||
'To continue, you must verify your identity by re-authenticating:' | ||
) | ||
).toBeInTheDocument(); | ||
expect(screen.getByText('Okta')).toBeInTheDocument(); | ||
expect(screen.getByTestId('close-dialog')).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays error text when provided', () => { | ||
const errorText = 'Authentication failed'; | ||
const mfa = makeMockState({ errorText }); | ||
render(<AuthnDialog mfa={mfa} onCancel={mockOnCancel} />); | ||
|
||
expect(screen.getByTestId('danger-alert')).toBeInTheDocument(); | ||
expect(screen.getByText(errorText)).toBeInTheDocument(); | ||
}); | ||
|
||
test('sso button renders with callback', async () => { | ||
const mfa = makeMockState({ | ||
ssoChallenge: mockSsoChallenge, | ||
onSsoAuthenticate: jest.fn(), | ||
}); | ||
render(<AuthnDialog mfa={mfa} onCancel={mockOnCancel} />); | ||
const ssoButton = screen.getByText('Okta'); | ||
fireEvent.click(ssoButton); | ||
expect(mfa.onSsoAuthenticate).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('webauthn button renders with callback', async () => { | ||
const mfa = makeMockState({ | ||
webauthnPublicKey: { challenge: new ArrayBuffer(0) }, | ||
onWebauthnAuthenticate: jest.fn(), | ||
}); | ||
render(<AuthnDialog mfa={mfa} onCancel={mockOnCancel} />); | ||
const webauthn = screen.getByText('Passkey or MFA Device'); | ||
fireEvent.click(webauthn); | ||
expect(mfa.onWebauthnAuthenticate).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.