Skip to content
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

fix: add "wire-" prefix for sso code [WPB-11927] #18477

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/script/auth/page/Index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {initialAuthState} from '../module/reducer/authReducer';
import {ROUTE} from '../route';
import {mockStoreFactory} from '../util/test/mockStoreFactory';
import {mountComponent} from '../util/test/TestUtil';
import {getPrefixedSSOCode} from '../util/urlUtil';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
Expand Down Expand Up @@ -71,7 +72,7 @@ describe('when visiting the index page', () => {
}),
);

expect(Navigate).toHaveBeenCalledWith({to: `${ROUTE.SSO}/wire-${defaultSSOCode}`}, {});
expect(Navigate).toHaveBeenCalledWith({to: `${ROUTE.SSO}/${getPrefixedSSOCode(defaultSSOCode)}`}, {});
});

it('shows the welcome text with default backend name', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/script/auth/page/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {bindActionCreators, RootState} from '../module/reducer';
import * as AuthSelector from '../module/selector/AuthSelector';
import {QUERY_KEY, ROUTE} from '../route';
import {logoutReasonStrings} from '../util/logoutUtil';
import {getPrefixedSSOCode} from '../util/urlUtil';

type Props = React.HTMLProps<HTMLDivElement>;

Expand All @@ -56,7 +57,7 @@ const IndexComponent = ({defaultSSOCode}: Props & ConnectedProps & DispatchProps

if (defaultSSOCode) {
// Redirect to prefilled SSO login if default SSO code is set on backend
return <Navigate to={`${ROUTE.SSO}/wire-${defaultSSOCode}`} />;
return <Navigate to={`${ROUTE.SSO}/${getPrefixedSSOCode(defaultSSOCode)}`} />;
}

const features = Config.getConfig().FEATURE;
Expand Down
5 changes: 3 additions & 2 deletions src/script/auth/page/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import * as ConversationSelector from '../module/selector/ConversationSelector';
import {QUERY_KEY, ROUTE} from '../route';
import {parseError, parseValidationErrors} from '../util/errorUtil';
import {getOAuthQueryString} from '../util/oauthUtil';
import {getPrefixedSSOCode} from '../util/urlUtil';
type Props = React.HTMLProps<HTMLDivElement> & {
embedded?: boolean;
};
Expand Down Expand Up @@ -156,7 +157,7 @@ const LoginComponent = ({
useEffect(() => {
// Redirect to prefilled SSO login if default SSO code is set on backend unless we're following the guest link flow
if (defaultSSOCode && !embedded) {
navigate(`${ROUTE.SSO}/${defaultSSOCode}`);
navigate(`${ROUTE.SSO}/${getPrefixedSSOCode(defaultSSOCode)}`);
}
}, [defaultSSOCode, embedded, navigate]);

Expand Down Expand Up @@ -474,7 +475,7 @@ const LoginComponent = ({
<Button
type="button"
variant={ButtonVariant.SECONDARY}
onClick={() => navigate(`${ROUTE.SSO}/${defaultSSOCode ?? ''}`)}
onClick={() => navigate(`${ROUTE.SSO}/${getPrefixedSSOCode(defaultSSOCode)}`)}
style={{marginTop: '16px'}}
data-uie-name="go-sso-login"
>
Expand Down
3 changes: 1 addition & 2 deletions src/script/auth/page/SingleSignOnForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ import * as ConversationSelector from '../module/selector/ConversationSelector';
import {QUERY_KEY, ROUTE} from '../route';
import {parseError, parseValidationErrors} from '../util/errorUtil';
import {logoutReasonStrings} from '../util/logoutUtil';
import {getSearchParams} from '../util/urlUtil';
import {getSearchParams, SSO_CODE_PREFIX} from '../util/urlUtil';

export interface SingleSignOnFormProps extends React.HTMLAttributes<HTMLDivElement> {
doLogin: (code: string) => Promise<void>;
initialCode?: string;
}

const SSO_CODE_PREFIX = 'wire-';
const SSO_CODE_PREFIX_REGEX = '[wW][iI][rR][eE]-';
const SingleSignOnFormComponent = ({
initialCode,
Expand Down
6 changes: 6 additions & 0 deletions src/script/auth/util/urlUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ export function openTab(url: string): Window {
}
return newWindow;
}

export const SSO_CODE_PREFIX = 'wire-';

export function getPrefixedSSOCode(code?: string) {
return code ? `${SSO_CODE_PREFIX}${code}` : '';
}
Loading