Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions web/packages/teleport/src/Login/Login.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,26 @@ test('show login form after modt acknowledge', async () => {
fireEvent.click(screen.getByText('Acknowledge'));
expect(screen.getByPlaceholderText(/username/i)).toBeInTheDocument();
});

test('skip motd if login initiated from headless auth', async () => {
// set global window.location with redirect url.
global.window = Object.create(window);
const url =
'https://teleport.example.com/web/login?redirect_uri=https://teleport.example.com/web/headless/5c5c1f73-ac5c-52ee-bc9e-0353094dcb4a';
Object.defineProperty(window, 'location', {
value: {
href: url,
},
});

jest
.spyOn(cfg, 'getMotd')
.mockImplementation(
() => 'Welcome to cluster, your activity will be recorded.'
);
render(<Login />);

expect(
screen.queryByText('Welcome to cluster, your activity will be recorded.')
).not.toBeInTheDocument();
});
11 changes: 10 additions & 1 deletion web/packages/teleport/src/Login/useLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ export default function useLogin() {
const auth2faType = cfg.getAuth2faType();
const isLocalAuthEnabled = cfg.getLocalAuthFlag();
const motd = cfg.getMotd();
const [showMotd, setShowMotd] = useState(!!motd);
const [showMotd, setShowMotd] = useState(() => {
const url = new URL(window.location.href);
Comment thread
flyinghermit marked this conversation as resolved.
Outdated
const redirect_uri = url.searchParams.get('redirect_uri');
Comment thread
flyinghermit marked this conversation as resolved.
Outdated

if (redirect_uri?.includes('headless')) {
return false;
} else if (cfg.getMotd()) {
return true;
}
Comment thread
flyinghermit marked this conversation as resolved.
Comment thread
flyinghermit marked this conversation as resolved.
});

function acknowledgeMotd() {
setShowMotd(false);
Expand Down