Skip to content

Commit

Permalink
feat: remove default withCredentials false as it is the default
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Dec 3, 2024
1 parent a5634ad commit 5f50318
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 73 deletions.
2 changes: 0 additions & 2 deletions src/core/infra/repositories/apiConfigBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const buildRequestConfig = (
headers: {
'Content-Type': contentType
},
withCredentials: false,
...(abortSignal && { signal: abortSignal })
}

Expand Down Expand Up @@ -48,7 +47,6 @@ export const buildRequestConfig = (
if (token) {
requestConfig.headers.Authorization = `Bearer ${token}`
}
requestConfig.withCredentials = false
break
}
}
Expand Down
16 changes: 6 additions & 10 deletions test/testHelpers/TestConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,21 @@ export class TestConstants {
headers: {
'Content-Type': 'application/json',
'X-Dataverse-Key': TestConstants.TEST_DUMMY_API_KEY
},
withCredentials: false
}
}
static readonly TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY_INCLUDE_DEACCESSIONED = {
params: { includeDeaccessioned: true },
headers: {
'Content-Type': 'application/json',
'X-Dataverse-Key': TestConstants.TEST_DUMMY_API_KEY
},
withCredentials: false
}
}
static readonly TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_SESSION_COOKIE = {
withCredentials: true,
params: {},
headers: {
'Content-Type': 'application/json'
}
},
withCredentials: true
}
static readonly TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_SESSION_COOKIE_INCLUDE_DEACCESSIONED =
{
Expand All @@ -47,16 +45,14 @@ export class TestConstants {
params: {},
headers: {
'Content-Type': 'application/json'
},
withCredentials: false
}
}
static readonly TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_BEARER_TOKEN = {
params: {},
headers: {
Authorization: `Bearer ${TestConstants.TEST_DUMMY_BEARER_TOKEN}`,
'Content-Type': 'application/json'
},
withCredentials: false
}
}

static readonly TEST_DUMMY_COLLECTION_ID = 10001
Expand Down
4 changes: 1 addition & 3 deletions test/unit/auth/BearerTokenMechanism.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ describe('BearerTokenMechanism', () => {
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_BEARER_TOKEN.headers,
params: {
returnOwners: true
},
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_BEARER_TOKEN.withCredentials
}
}

jest.spyOn(axios, 'get').mockResolvedValue(testCollectionSuccessfulResponse)
Expand Down
24 changes: 6 additions & 18 deletions test/unit/collections/CollectionsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ describe('CollectionsRepository', () => {
params: {
returnOwners: true
},
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}

describe('by numeric id', () => {
Expand Down Expand Up @@ -264,9 +262,7 @@ describe('CollectionsRepository', () => {
params: {
returnDetails: true
},
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}

test('should return facets when providing a valid id', async () => {
Expand Down Expand Up @@ -399,9 +395,7 @@ describe('CollectionsRepository', () => {

const expectedRequestConfigApiKey = {
params: expectedRequestParams,
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}

expect(axios.get).toHaveBeenCalledWith(expectedApiEndpoint, expectedRequestConfigApiKey)
Expand Down Expand Up @@ -444,9 +438,7 @@ describe('CollectionsRepository', () => {

const expectedRequestConfigApiKeyWithPagination = {
params: expectedRequestParamsWithPagination,
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}

expect(axios.get).toHaveBeenCalledWith(
Expand Down Expand Up @@ -489,9 +481,7 @@ describe('CollectionsRepository', () => {

const expectedRequestConfigApiKeyWithCollectionId = {
params: expectedRequestParamsWithCollectionId,
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}

expect(axios.get).toHaveBeenCalledWith(
Expand Down Expand Up @@ -531,9 +521,7 @@ describe('CollectionsRepository', () => {

const expectedRequestConfigApiKey = {
params: expectedRequestParams,
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}

expect(axios.get).toHaveBeenCalledWith(expectedApiEndpoint, expectedRequestConfigApiKey)
Expand Down
15 changes: 4 additions & 11 deletions test/unit/datasets/DatasetsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ describe('DatasetsRepository', () => {
excludeFiles: true,
returnOwners: true
},
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}
const expectedRequestConfigSessionCookie = {
params: {
Expand Down Expand Up @@ -292,8 +290,7 @@ describe('DatasetsRepository', () => {
describe('getPrivateUrlDataset', () => {
const expectedRequestConfig = {
params: { returnOwners: true },
headers: TestConstants.TEST_EXPECTED_UNAUTHENTICATED_REQUEST_CONFIG.headers,
withCredentials: TestConstants.TEST_EXPECTED_UNAUTHENTICATED_REQUEST_CONFIG.withCredentials
headers: TestConstants.TEST_EXPECTED_UNAUTHENTICATED_REQUEST_CONFIG.headers
}
test('should return Dataset when response is successful', async () => {
jest.spyOn(axios, 'get').mockResolvedValue(testDatasetVersionSuccessfulResponse)
Expand Down Expand Up @@ -644,9 +641,7 @@ describe('DatasetsRepository', () => {

const expectedRequestConfigApiKeyWithPagination = {
params: expectedRequestParamsWithPagination,
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}

expect(axios.get).toHaveBeenCalledWith(
Expand Down Expand Up @@ -688,9 +683,7 @@ describe('DatasetsRepository', () => {

const expectedRequestConfigApiKeyWithCollectionId = {
params: expectedRequestParamsWithCollectionId,
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}

expect(axios.get).toHaveBeenCalledWith(
Expand Down
3 changes: 1 addition & 2 deletions test/unit/files/DirectUploadClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ describe('uploadFile', () => {
`${ApiConfig.dataverseApiUrl}/datasets/mpupload/testAbort`,
{
headers: { 'Content-Type': 'application/json', 'X-Dataverse-Key': 'dummyApiKey' },
params: {},
withCredentials: false
params: {}
}
)
})
Expand Down
32 changes: 8 additions & 24 deletions test/unit/files/FilesRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ describe('FilesRepository', () => {
params: {
size: testFileSize
},
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}
const expectedRequestConfigSessionCookie = {
params: {
Expand Down Expand Up @@ -245,9 +243,7 @@ describe('FilesRepository', () => {
includeDeaccessioned: testIncludeDeaccessioned,
orderCriteria: testFileOrderCriteria
},
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}
const expectedRequestConfigSessionCookie = {
params: {
Expand All @@ -272,9 +268,7 @@ describe('FilesRepository', () => {

const expectedRequestConfigApiKeyWithOptional = {
params: expectedRequestParamsWithOptional,
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}

const expectedFiles = createFilesSubsetModel(testTotalCount)
Expand Down Expand Up @@ -434,9 +428,7 @@ describe('FilesRepository', () => {

const expectedRequestConfigApiKey = {
params: { includeDeaccessioned: testIncludeDeaccessioned },
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}
const expectedRequestConfigSessionCookie = {
params: { includeDeaccessioned: testIncludeDeaccessioned },
Expand All @@ -455,9 +447,7 @@ describe('FilesRepository', () => {

const expectedRequestConfigApiKeyWithOptional = {
params: expectedRequestParamsWithOptional,
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}

const expectedCount = createFileCountsModel()
Expand Down Expand Up @@ -589,9 +579,7 @@ describe('FilesRepository', () => {
mode: FileDownloadSizeMode.ARCHIVAL.toString(),
includeDeaccessioned: testIncludeDeaccessioned
},
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}
const expectedRequestConfigSessionCookie = {
params: {
Expand All @@ -611,9 +599,7 @@ describe('FilesRepository', () => {
categoryName: testFileCriteria.categoryName,
tabularTagName: testFileCriteria.tabularTagName
},
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}
const expectedApiEndpoint = `${TestConstants.TEST_API_URL}/datasets/${testDatasetId}/versions/${testDatasetVersionId}/downloadsize`

Expand Down Expand Up @@ -1036,9 +1022,7 @@ describe('FilesRepository', () => {

const expectedRequestConfigApiKey = {
params: expectedRequestParams,
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers,
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers
}

const expectedRequestConfigSessionCookie = {
Expand Down
4 changes: 1 addition & 3 deletions test/unit/metadataBlocks/MetadataBlocksRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ describe('MetadataBlocksRepository', () => {
params: {
onlyDisplayedOnCreate: true,
returnDatasetFieldTypes: true
},
withCredentials:
TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.withCredentials
}
}

test('should return collection metadata blocks on successful response', async () => {
Expand Down

0 comments on commit 5f50318

Please sign in to comment.