Skip to content
Snippets Groups Projects
Commit 381d0106 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

fix: ensure trailing slash for datasource baseUrls

parent 07d3afcd
No related branches found
No related tags found
No related merge requests found
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`datasource/helm getReleases returns list of versions for normal response if index.yaml is not cached 1`] = ` exports[`datasource/helm getReleases returns list of versions for normal response 1`] = `
Object { Object {
"homepage": "https://www.getambassador.io/", "homepage": "https://www.getambassador.io/",
"name": "ambassador", "name": "ambassador",
......
...@@ -21,7 +21,7 @@ describe('datasource/helm', () => { ...@@ -21,7 +21,7 @@ describe('datasource/helm', () => {
expect( expect(
await getReleases({ await getReleases({
lookupName: undefined, lookupName: undefined,
registryUrls: ['example-repository.com'], registryUrls: ['https://example-repository.com'],
}) })
).toBeNull(); ).toBeNull();
}); });
...@@ -38,7 +38,7 @@ describe('datasource/helm', () => { ...@@ -38,7 +38,7 @@ describe('datasource/helm', () => {
expect( expect(
await getReleases({ await getReleases({
lookupName: 'non_existent_chart', lookupName: 'non_existent_chart',
registryUrls: ['example-repository.com'], registryUrls: ['https://example-repository.com'],
}) })
).toBeNull(); ).toBeNull();
}); });
...@@ -49,7 +49,7 @@ describe('datasource/helm', () => { ...@@ -49,7 +49,7 @@ describe('datasource/helm', () => {
expect( expect(
await getReleases({ await getReleases({
lookupName: 'non_existent_chart', lookupName: 'non_existent_chart',
registryUrls: ['example-repository.com'], registryUrls: ['https://example-repository.com'],
}) })
).toBeNull(); ).toBeNull();
}); });
...@@ -62,7 +62,7 @@ describe('datasource/helm', () => { ...@@ -62,7 +62,7 @@ describe('datasource/helm', () => {
expect( expect(
await getReleases({ await getReleases({
lookupName: 'some_chart', lookupName: 'some_chart',
registryUrls: ['example-repository.com'], registryUrls: ['https://example-repository.com'],
}) })
).toBeNull(); ).toBeNull();
}); });
...@@ -76,7 +76,7 @@ describe('datasource/helm', () => { ...@@ -76,7 +76,7 @@ describe('datasource/helm', () => {
try { try {
await getReleases({ await getReleases({
lookupName: 'some_chart', lookupName: 'some_chart',
registryUrls: ['example-repository.com'], registryUrls: ['https://example-repository.com'],
}); });
} catch (err) { } catch (err) {
e = err; e = err;
...@@ -91,7 +91,7 @@ describe('datasource/helm', () => { ...@@ -91,7 +91,7 @@ describe('datasource/helm', () => {
expect( expect(
await getReleases({ await getReleases({
lookupName: 'some_chart', lookupName: 'some_chart',
registryUrls: ['example-repository.com'], registryUrls: ['https://example-repository.com'],
}) })
).toBeNull(); ).toBeNull();
}); });
...@@ -100,7 +100,7 @@ describe('datasource/helm', () => { ...@@ -100,7 +100,7 @@ describe('datasource/helm', () => {
got.mockReturnValueOnce(res); got.mockReturnValueOnce(res);
const releases = await getReleases({ const releases = await getReleases({
lookupName: 'non_existent_chart', lookupName: 'non_existent_chart',
registryUrls: ['example-repository.com'], registryUrls: ['https://example-repository.com'],
}); });
expect(releases).toBeNull(); expect(releases).toBeNull();
}); });
...@@ -114,7 +114,7 @@ describe('datasource/helm', () => { ...@@ -114,7 +114,7 @@ describe('datasource/helm', () => {
got.mockReturnValueOnce(res); got.mockReturnValueOnce(res);
const releases = await getReleases({ const releases = await getReleases({
lookupName: 'non_existent_chart', lookupName: 'non_existent_chart',
registryUrls: ['example-repository.com'], registryUrls: ['https://example-repository.com'],
}); });
expect(releases).toBeNull(); expect(releases).toBeNull();
}); });
...@@ -122,18 +122,28 @@ describe('datasource/helm', () => { ...@@ -122,18 +122,28 @@ describe('datasource/helm', () => {
got.mockReturnValueOnce({ body: indexYaml }); got.mockReturnValueOnce({ body: indexYaml });
const releases = await getReleases({ const releases = await getReleases({
lookupName: 'non_existent_chart', lookupName: 'non_existent_chart',
registryUrls: ['example-repository.com'], registryUrls: ['https://example-repository.com'],
}); });
expect(releases).toBeNull(); expect(releases).toBeNull();
}); });
it('returns list of versions for normal response if index.yaml is not cached', async () => { it('returns list of versions for normal response', async () => {
got.mockReturnValueOnce({ body: indexYaml }); got.mockReturnValueOnce({ body: indexYaml });
const releases = await getReleases({ const releases = await getReleases({
lookupName: 'ambassador', lookupName: 'ambassador',
registryUrls: ['example-repository.com'], registryUrls: ['https://example-repository.com'],
}); });
expect(releases).not.toBeNull(); expect(releases).not.toBeNull();
expect(releases).toMatchSnapshot(); expect(releases).toMatchSnapshot();
}); });
it('adds trailing slash to subdirectories', async () => {
got.mockReturnValueOnce({ body: indexYaml });
await getReleases({
lookupName: 'ambassador',
registryUrls: ['https://example-repository.com/subdir'],
});
expect(got.mock.calls[0][0]).toEqual(
'https://example-repository.com/subdir/index.yaml'
);
});
}); });
}); });
...@@ -3,6 +3,7 @@ import yaml from 'js-yaml'; ...@@ -3,6 +3,7 @@ import yaml from 'js-yaml';
import { logger } from '../../logger'; import { logger } from '../../logger';
import * as globalCache from '../../util/cache/global'; import * as globalCache from '../../util/cache/global';
import { Http } from '../../util/http'; import { Http } from '../../util/http';
import { ensureTrailingSlash } from '../../util/url';
import { DatasourceError, GetReleasesConfig, ReleaseResult } from '../common'; import { DatasourceError, GetReleasesConfig, ReleaseResult } from '../common';
export const id = 'helm'; export const id = 'helm';
...@@ -25,7 +26,9 @@ export async function getRepositoryData( ...@@ -25,7 +26,9 @@ export async function getRepositoryData(
} }
let res: any; let res: any;
try { try {
res = await http.get('index.yaml', { baseUrl: repository }); res = await http.get('index.yaml', {
baseUrl: ensureTrailingSlash(repository),
});
if (!res || !res.body) { if (!res || !res.body) {
logger.warn(`Received invalid response from ${repository}`); logger.warn(`Received invalid response from ${repository}`);
return null; return null;
......
...@@ -2,6 +2,7 @@ import { OutgoingHttpHeaders } from 'http'; ...@@ -2,6 +2,7 @@ import { OutgoingHttpHeaders } from 'http';
import { logger } from '../../logger'; import { logger } from '../../logger';
import { Http } from '../../util/http'; import { Http } from '../../util/http';
import { maskToken } from '../../util/mask'; import { maskToken } from '../../util/mask';
import { ensureTrailingSlash } from '../../util/url';
import { ReleaseResult } from '../common'; import { ReleaseResult } from '../common';
import { id } from './common'; import { id } from './common';
import { FORBIDDEN, NOT_FOUND, UNAUTHORIZED } from './errors'; import { FORBIDDEN, NOT_FOUND, UNAUTHORIZED } from './errors';
...@@ -39,7 +40,7 @@ const fetch = async ({ dependency, registry, path }): Promise<any> => { ...@@ -39,7 +40,7 @@ const fetch = async ({ dependency, registry, path }): Promise<any> => {
const headers = getHeaders(); const headers = getHeaders();
const name = `${path}/${dependency}.json`; const name = `${path}/${dependency}.json`;
const baseUrl = registry; const baseUrl = ensureTrailingSlash(registry);
logger.trace({ dependency }, `RubyGems lookup request: ${baseUrl} ${name}`); logger.trace({ dependency }, `RubyGems lookup request: ${baseUrl} ${name}`);
const response = (await http.getJson(name, { baseUrl, headers })) || { const response = (await http.getJson(name, { baseUrl, headers })) || {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment