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

[DO NOT MERGE] Do not throw other then unauthorised error on token refresh #990

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ describe('OAuth service', () => {
try {
await OAuthService.refreshTokenIfNeeded(devWorkspace);
} catch (e: any) {
expect(e.response.data.responseData.attributes.oauth_authentication_url).toBe(
'https://git-lub/oauth/url',
);
fail('it should not reach here');
}

expect(refreshFactoryOauthTokenSpy).toHaveBeenCalledWith('origin:project');
Expand Down Expand Up @@ -229,10 +227,53 @@ describe('OAuth service', () => {
try {
await OAuthService.refreshTokenIfNeeded(devWorkspace);
} catch (e: any) {
expect(e.response.status).toBe(401);
fail('it should not reach here');
}

expect(refreshFactoryOauthTokenSpy).toHaveBeenCalledWith('origin:project');
expect(mockOpenOAuthPage).not.toHaveBeenCalled();
});

it('should redirect to oauth window if error has OAuth response', async () => {
const status = { mainUrl: 'https://mainUrl' };
const projects = [
{
name: 'project',
git: {
remotes: {
origin: 'origin:project',
},
},
},
];
const devWorkspace = new DevWorkspaceBuilder()
.withStatus(status)
.withProjects(projects)
.build();

refreshFactoryOauthTokenSpy.mockRejectedValueOnce({
isAxiosError: false,
code: '401',
response: {
status: 401,
data: {
attributes: {
oauth_provider: 'git-lab',
oauth_authentication_url: 'https://git-lub/oauth/url',
},
},
},
} as AxiosError);

jest.spyOn(common.helpers.errors, 'includesAxiosResponse').mockImplementation(() => true);

try {
await OAuthService.refreshTokenIfNeeded(devWorkspace);
} catch (e: any) {
expect(e.response.status).toBe(401);
}

expect(refreshFactoryOauthTokenSpy).toHaveBeenCalledWith('origin:project');
expect(mockOpenOAuthPage).toHaveBeenCalled();
});
});
4 changes: 3 additions & 1 deletion packages/dashboard-frontend/src/services/oauth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ export default class OAuthService {
response.data.attributes.oauth_authentication_url,
redirectUrl.toString(),
);
// Interrupt the workspace start. The workspace should start again after the authentication.
throw e;
}
throw e;
// Skip other exceptions to proceed the workspace start.
}
}
}
Expand Down
Loading