Skip to content

Commit

Permalink
Fixed: sending credentials in requests only when it is required
Browse files Browse the repository at this point in the history
  • Loading branch information
GPortas committed May 9, 2023
1 parent e6872c1 commit 18243bc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/core/infra/repositories/ApiRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { WriteError } from '../../domain/repositories/WriteError';
For 2.0.0, we must also support API key auth to be backwards compatible and support use cases other than SPA MVP.
*/
export abstract class ApiRepository {
public async doGet(apiEndpoint: string): Promise<AxiosResponse> {
public async doGet(apiEndpoint: string, withCredentials: boolean = false): Promise<AxiosResponse> {
return await axios
.get(this.buildRequestUrl(apiEndpoint), { withCredentials: true })
.get(this.buildRequestUrl(apiEndpoint), { withCredentials: withCredentials })
.then((response) => response)
.catch((error) => {
throw new ReadError(
Expand Down
2 changes: 1 addition & 1 deletion src/users/infra/repositories/UsersRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AxiosResponse } from 'axios';

export class UsersRepository extends ApiRepository implements IUsersRepository {
public async getCurrentAuthenticatedUser(): Promise<AuthenticatedUser> {
return this.doGet('/users/:me')
return this.doGet('/users/:me', true)
.then((response) => this.getAuthenticatedUserFromResponse(response))
.catch((error) => {
throw error;
Expand Down
4 changes: 2 additions & 2 deletions test/unit/info/DataverseInfoRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('getDataverseVersion', () => {

const actual = await sut.getDataverseVersion();

assert.calledWithExactly(axiosGetStub, `${testApiUrl}/info/version`, { withCredentials: true });
assert.calledWithExactly(axiosGetStub, `${testApiUrl}/info/version`, { withCredentials: false });
assert.match(actual.number, testVersionNumber);
assert.match(actual.build, testVersionBuild);
});
Expand All @@ -49,7 +49,7 @@ describe('getDataverseVersion', () => {
let error: ReadError = undefined;
await sut.getDataverseVersion().catch((e) => (error = e));

assert.calledWithExactly(axiosGetStub, `${testApiUrl}/info/version`, { withCredentials: true });
assert.calledWithExactly(axiosGetStub, `${testApiUrl}/info/version`, { withCredentials: false });
expect(error).to.be.instanceOf(Error);
});
});

0 comments on commit 18243bc

Please sign in to comment.