-
Notifications
You must be signed in to change notification settings - Fork 2.1k
add questionnaire to onboarding #28119
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
178 changes: 178 additions & 0 deletions
178
web/packages/teleport/src/Welcome/NewCredentials/NewCredentials.test.tsx
This file contains hidden or 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,178 @@ | ||
| /** | ||
| * Copyright 2023 Gravitational, Inc | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { Attempt } from 'shared/hooks/useAttemptNext'; | ||
|
|
||
| import { render, screen } from 'design/utils/testing'; | ||
| import React from 'react'; | ||
|
|
||
| import { RecoveryCodes, ResetToken } from 'teleport/services/auth'; | ||
| import { NewCredentialsProps } from 'teleport/Welcome/NewCredentials/types'; | ||
| import { NewCredentials } from 'teleport/Welcome/NewCredentials/NewCredentials'; | ||
| import { mockUserContextProviderWith } from 'teleport/User/testHelpers/mockUserContextWith'; | ||
| import { makeTestUserContext } from 'teleport/User/testHelpers/makeTestUserContext'; | ||
|
|
||
| const attempt: Attempt = { status: '' }; | ||
| const failedAttempt: Attempt = { status: 'failed' }; | ||
| const processingAttempt: Attempt = { status: 'processing' }; | ||
| const successAttempt: Attempt = { status: 'success', statusText: 'hey' }; | ||
|
|
||
| const resetToken: ResetToken = { | ||
| tokenId: 'tokenId', | ||
| qrCode: 'qrCode', | ||
| user: 'user', | ||
| }; | ||
| const recoveryCodes: RecoveryCodes = { | ||
| createdDate: new Date(), | ||
| }; | ||
|
|
||
| const makeProps = (): NewCredentialsProps => { | ||
| return { | ||
| auth2faType: 'off', | ||
| primaryAuthType: 'sso', | ||
| isPasswordlessEnabled: false, | ||
| fetchAttempt: attempt, | ||
| submitAttempt: attempt, | ||
| clearSubmitAttempt: () => {}, | ||
| onSubmit: () => {}, | ||
| onSubmitWithWebauthn: () => {}, | ||
| resetToken: resetToken, | ||
| recoveryCodes: recoveryCodes, | ||
| redirect: () => {}, | ||
| success: false, | ||
| finishedRegister: () => {}, | ||
| privateKeyPolicyEnabled: false, | ||
| displayOnboardingQuestionnaire: false, | ||
| setDisplayOnboardingQuestionnaire: () => {}, | ||
| resetMode: false, | ||
| isDashboard: false, | ||
| }; | ||
| }; | ||
|
|
||
| test('renders expired for failed fetch attempt', () => { | ||
| const props = makeProps(); | ||
| props.fetchAttempt = failedAttempt; | ||
| render(<NewCredentials {...props} />); | ||
|
|
||
| expect(screen.getByText(/Invitation Code Expired/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const nullCases: { | ||
| attempt: Attempt; | ||
| }[] = [{ attempt: processingAttempt }, { attempt: attempt }]; | ||
|
|
||
| test.each(nullCases)('renders $attempt as null', testCase => { | ||
| const props = makeProps(); | ||
| props.fetchAttempt = testCase.attempt; | ||
| const { container } = render(<NewCredentials {...props} />); | ||
|
|
||
| expect(container).toBeEmptyDOMElement(); | ||
| }); | ||
|
|
||
| test('renders Reset Complete for success and private key policy enabled during reset', () => { | ||
| const props = makeProps(); | ||
| props.fetchAttempt = successAttempt; | ||
| props.success = true; | ||
| props.privateKeyPolicyEnabled = true; | ||
| props.resetMode = true; | ||
| render(<NewCredentials {...props} />); | ||
|
|
||
| expect(screen.getByText(/Reset Complete/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders Registration Complete for success and private key policy enabled during registration', () => { | ||
| const props = makeProps(); | ||
| props.fetchAttempt = { status: 'success' }; | ||
| props.success = true; | ||
| props.privateKeyPolicyEnabled = true; | ||
| props.resetMode = false; | ||
| render(<NewCredentials {...props} />); | ||
|
|
||
| expect(screen.getByText(/Registration Complete/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders Register Success on success', () => { | ||
| const props = makeProps(); | ||
| props.fetchAttempt = { status: 'success' }; | ||
| props.privateKeyPolicyEnabled = false; | ||
| props.recoveryCodes = undefined; | ||
| props.success = true; | ||
| render(<NewCredentials {...props} />); | ||
|
|
||
| expect( | ||
| screen.getByText(/Proceed to access your account./i) | ||
| ).toBeInTheDocument(); | ||
| expect(screen.getByText(/Go to Cluster/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders recovery codes', () => { | ||
| const props = makeProps(); | ||
| props.fetchAttempt = { status: 'success' }; | ||
| props.success = false; | ||
| props.recoveryCodes = { | ||
| codes: ['foo', 'bar'], | ||
| createdDate: new Date(), | ||
| }; | ||
| render(<NewCredentials {...props} />); | ||
|
|
||
| expect(screen.getByText(/Backup & Recovery Codes/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders credential flow for passwordless', () => { | ||
| const props = makeProps(); | ||
| props.fetchAttempt = { status: 'success' }; | ||
| props.success = false; | ||
| props.recoveryCodes = undefined; | ||
| props.primaryAuthType = 'passwordless'; | ||
| render(<NewCredentials {...props} />); | ||
|
|
||
| expect(screen.getByText(/Set A Passwordless Device/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders credential flow for local', () => { | ||
| const props = makeProps(); | ||
| props.fetchAttempt = { status: 'success' }; | ||
| props.success = false; | ||
| props.recoveryCodes = undefined; | ||
| props.primaryAuthType = 'local'; | ||
| render(<NewCredentials {...props} />); | ||
|
|
||
| expect(screen.getByText(/Set A Password/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders credential flow for sso', () => { | ||
| const props = makeProps(); | ||
| props.fetchAttempt = { status: 'success' }; | ||
| props.success = false; | ||
| props.recoveryCodes = undefined; | ||
| props.primaryAuthType = 'sso'; | ||
| render(<NewCredentials {...props} />); | ||
|
|
||
| expect(screen.getByText(/Set A Password/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders questionnaire', () => { | ||
| mockUserContextProviderWith(makeTestUserContext()); | ||
|
|
||
| const props = makeProps(); | ||
| props.fetchAttempt = { status: 'success' }; | ||
| props.success = true; | ||
| props.recoveryCodes = undefined; | ||
| props.displayOnboardingQuestionnaire = true; | ||
| render(<NewCredentials {...props} />); | ||
|
|
||
| expect(screen.getByText(/Tell us about yourself/i)).toBeInTheDocument(); | ||
| }); |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -17,17 +17,17 @@ limitations under the License. | |
| import React, { useState } from 'react'; | ||
| import { Card } from 'design'; | ||
| import { PrimaryAuthType } from 'shared/services'; | ||
|
|
||
| import { NewFlow, StepComponentProps, StepSlider } from 'design/StepSlider'; | ||
|
|
||
| import RecoveryCodes from 'teleport/components/RecoveryCodes'; | ||
| import { PrivateKeyLoginDisabledCard } from 'teleport/components/PrivateKeyPolicy'; | ||
|
|
||
| import { Questionnaire } from 'teleport/Welcome/Questionnaire/Questionnaire'; | ||
| import cfg from 'teleport/config'; | ||
|
|
||
| import useToken, { State } from '../useToken'; | ||
| import useToken from '../useToken'; | ||
|
|
||
| import { Expired } from './Expired'; | ||
| import { NewCredentialsProps } from './types'; | ||
| import { RegisterSuccess } from './Success'; | ||
| import { NewMfaDevice } from './NewMfaDevice'; | ||
| import { NewPasswordlessDevice } from './NewPasswordlessDevice'; | ||
|
|
@@ -54,7 +54,7 @@ export function Container({ tokenId = '', resetMode = false }) { | |
| ); | ||
| } | ||
|
|
||
| export function NewCredentials(props: State & Props) { | ||
| export function NewCredentials(props: NewCredentialsProps) { | ||
| const { | ||
| fetchAttempt, | ||
| recoveryCodes, | ||
|
|
@@ -66,8 +66,20 @@ export function NewCredentials(props: State & Props) { | |
| finishedRegister, | ||
| privateKeyPolicyEnabled, | ||
| isDashboard, | ||
| displayOnboardingQuestionnaire, | ||
| setDisplayOnboardingQuestionnaire, | ||
| } = props; | ||
|
|
||
| // Check which flow to render as default. | ||
| const [password, setPassword] = useState(''); | ||
| const [newFlow, setNewFlow] = useState<NewFlow<LoginFlow>>(); | ||
| const [flow, setFlow] = useState<LoginFlow>(() => { | ||
| if (primaryAuthType === 'sso' || primaryAuthType === 'local') { | ||
| return 'local'; | ||
| } | ||
| return 'passwordless'; | ||
| }); | ||
|
|
||
| if (fetchAttempt.status === 'failed') { | ||
| return <Expired resetMode={resetMode} />; | ||
| } | ||
|
|
@@ -84,6 +96,17 @@ export function NewCredentials(props: State & Props) { | |
| ); | ||
| } | ||
|
|
||
| if (success && !resetMode && displayOnboardingQuestionnaire) { | ||
| // todo (michellescripts) check cluster config to determine if all or partial questions are asked | ||
|
Contributor
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. Follow up PR |
||
| return ( | ||
| <Questionnaire | ||
| full={true} | ||
| username={resetToken.user} | ||
| onSubmit={() => setDisplayOnboardingQuestionnaire(false)} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| if (success) { | ||
| return ( | ||
| <RegisterSuccess | ||
|
|
@@ -106,16 +129,7 @@ export function NewCredentials(props: State & Props) { | |
| ); | ||
| } | ||
|
|
||
| // Check which flow to render as default. | ||
| const [password, setPassword] = useState(''); | ||
| const [newFlow, setNewFlow] = useState<NewFlow<LoginFlow>>(); | ||
| const [flow, setFlow] = useState<LoginFlow>(() => { | ||
| if (primaryAuthType === 'sso' || primaryAuthType === 'local') { | ||
| return 'local'; | ||
| } | ||
| return 'passwordless'; | ||
| }); | ||
|
|
||
| // display credentials flow | ||
| function onSwitchFlow(flow: LoginFlow) { | ||
| setFlow(flow); | ||
| } | ||
|
|
@@ -143,8 +157,3 @@ export function NewCredentials(props: State & Props) { | |
| </Card> | ||
| ); | ||
| } | ||
|
|
||
| export type Props = State & { | ||
| resetMode?: boolean; | ||
| isDashboard: boolean; | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love thoughts on this change. Are we still secure if leveraging
WithAuthCookieAndCSRF?We set a bearer token on redirect to
/webat the end of the registration. Until then, there is no bearer token to check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh, i'm not sure either... i would love to know a definite answer though, because i have questions, like why not all protected endpoints use that too then? (perhaps these endpoints where it's used, the consequence aren't as high?) and also why didn't we pass the access token instead of the csrf token in the form? (this form is located where user was already authenticated)
but i took a look at
WithAuthCookieAndCSRFand it's intended fornon-ajaxrequest (forms) so I would generally stay away from it.i wonder if we can use local storage to temporarily store the user preference, then on init, we can update user preference there, and then delete that storage key?