Skip to content

Commit

Permalink
SCANNPM-42 Allow scan to run without a token provided (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-paulger-sonarsource authored Aug 14, 2024
1 parent a7143c2 commit 182af86
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sonarqube-scanner",
"description": "SonarQube/SonarCloud Scanner for the JavaScript world",
"version": "4.2.0",
"version": "4.2.1",
"homepage": "https://github.com/SonarSource/sonar-scanner-npm",
"author": {
"name": "Fabrice Bellingard",
Expand Down
4 changes: 1 addition & 3 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ export async function initializeAxios(properties: ScannerProperties) {
_axiosInstances = {
internal: axios.create({
baseURL,
headers: {
Authorization: `Bearer ${token}`,
},
headers: token ? { Authorization: `Bearer ${token}` } : {},
timeout,
...agents,
}),
Expand Down
18 changes: 18 additions & 0 deletions test/unit/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ describe('request', () => {
timeout: 23000,
});
});

it('should initialize axios without token', async () => {
jest.spyOn(axios, 'create');

await initializeAxios({
[ScannerProperty.SonarHostUrl]: SONARCLOUD_URL,
[ScannerProperty.SonarScannerApiBaseUrl]: SONARCLOUD_API_BASE_URL,
});

expect(axios.create).toHaveBeenCalledWith({
baseURL: SONARCLOUD_API_BASE_URL,
headers: {},
timeout: 0,
});
expect(axios.create).toHaveBeenCalledWith({
timeout: 0,
});
});
});

describe('fetch', () => {
Expand Down

0 comments on commit 182af86

Please sign in to comment.