Skip to content

Commit

Permalink
fix: allow gitlabUrl without scheme (#362)
Browse files Browse the repository at this point in the history
Fixes #360
 
Co-authored-by: Julian Beisert <julianbeisert@googlemail.com>
Co-authored-by: Florian Greinacher <florian@greinacher.de>
  • Loading branch information
Babbafett committed Apr 13, 2022
1 parent 3051799 commit bea6b3c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/resolve-config.js
Expand Up @@ -63,7 +63,10 @@ function shouldProxy(gitlabUrl, NO_PROXY) {
ws: 80,
wss: 443,
};
const parsedUrl = typeof gitlabUrl === 'string' ? new URL(gitlabUrl) : gitlabUrl || {};
const parsedUrl =
typeof gitlabUrl === 'string' && (gitlabUrl.startsWith('http://') || gitlabUrl.startsWith('https://'))
? new URL(gitlabUrl)
: gitlabUrl || {};
let proto = parsedUrl.protocol;
let hostname = parsedUrl.host;
let {port} = parsedUrl;
Expand Down
46 changes: 46 additions & 0 deletions test/resolve-config.test.js
Expand Up @@ -91,6 +91,52 @@ test('Returns user config via alternative environment variables', t => {
);
});

test('Returns user config via alternative environment variables with https proxy and no proto scheme set', t => {
const gitlabToken = 'TOKEN';
const gitlabUrl = 'host.com';
const gitlabApiPathPrefix = '/api/prefix';
const assets = ['file.js'];
// Testing with 8080 port because HttpsProxyAgent ignores 80 port with http protocol
const proxyUrl = 'http://proxy.test:8443';

const result = resolveConfig(
{assets},
{
env: {
GL_TOKEN: gitlabToken,
GL_URL: gitlabUrl,
GL_PREFIX: gitlabApiPathPrefix,
HTTPS_PROXY: proxyUrl,
},
}
);

t.deepEqual(result.proxy, {});
});

test('Returns user config via alternative environment variables with http proxy and no proto scheme set', t => {
const gitlabToken = 'TOKEN';
const gitlabUrl = 'host.com';
const gitlabApiPathPrefix = '/api/prefix';
const assets = ['file.js'];
// Testing with 8080 port because HttpsProxyAgent ignores 80 port with http protocol
const proxyUrl = 'http://proxy.test:8080';

const result = resolveConfig(
{assets},
{
env: {
GL_TOKEN: gitlabToken,
GL_URL: gitlabUrl,
GL_PREFIX: gitlabApiPathPrefix,
HTTP_PROXY: proxyUrl,
},
}
);

t.deepEqual(result.proxy, {});
});

test('Returns user config via alternative environment variables with http proxy', t => {
const gitlabToken = 'TOKEN';
const gitlabUrl = 'http://host.com';
Expand Down

0 comments on commit bea6b3c

Please sign in to comment.