Skip to content

Commit

Permalink
Merge 342f553 into 3883289
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Oct 27, 2022
2 parents 3883289 + 342f553 commit 4802143
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/HttpLoginHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export class HttpLoginHandler {
this.session.handleIncomingRedirect(`http://localhost:${this.port}${req.url}`)
.then(resolve, reject);
res.writeHead(200);
res.end(`<script>window.location = new URL('http://localhost:${this.port}/done'); window.close();</script>`);
} else if (req.url!.startsWith('/done')) {
res.writeHead(200);
res.end(`<script>window.close();</script>`);
} else {
res.writeHead(404);
Expand Down
27 changes: 25 additions & 2 deletions test/HttpLoginHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ describe('HttpLoginHandler', () => {
requestHandler({
url: '/onLoggedIn',
}, res);

requestHandler({
url: '/done',
}, res);
}),
info: {
isLoggedIn: true,
Expand All @@ -74,7 +78,24 @@ describe('HttpLoginHandler', () => {
expect(open).toHaveBeenCalledWith('http://example.org/authenticate');
expect(session.handleIncomingRedirect).toHaveBeenCalledWith('http://localhost:3005/onLoggedIn');
expect(res.writeHead).toHaveBeenCalledWith(200);
expect(res.end).toHaveBeenCalledWith('<script>window.close();</script>');
expect(res.end).toHaveBeenCalledWith(
'<script>window.location = new URL(\'http://localhost:3005/done\'); window.close();</script>',
);

expect(server.close).toHaveBeenCalledWith();
expect(socket.destroy).toHaveBeenCalledWith();

await open('http://localhost:3005/done');
});

it('handles a valid post-login sequence', async() => {
await handler.handleLogin({});

await open('http://localhost:3005/done');
expect(res.writeHead).toHaveBeenCalledWith(200);
expect(res.end).toHaveBeenCalledWith(
'<script>window.close();</script>',
);

expect(server.close).toHaveBeenCalledWith();
expect(socket.destroy).toHaveBeenCalledWith();
Expand All @@ -98,7 +119,9 @@ describe('HttpLoginHandler', () => {
expect(handleRedirect).toHaveBeenCalledWith('http://example.org/authenticate');
expect(session.handleIncomingRedirect).toHaveBeenCalledWith('http://localhost:3005/onLoggedIn');
expect(res.writeHead).toHaveBeenCalledWith(200);
expect(res.end).toHaveBeenCalledWith('<script>window.close();</script>');
expect(res.end).toHaveBeenCalledWith(
'<script>window.location = new URL(\'http://localhost:3005/done\'); window.close();</script>',
);

expect(server.close).toHaveBeenCalledWith();
expect(socket.destroy).toHaveBeenCalledWith();
Expand Down

0 comments on commit 4802143

Please sign in to comment.