Skip to content

Commit bea6b3c

Browse files
fix: allow gitlabUrl without scheme (#362)
Fixes #360 Co-authored-by: Julian Beisert <[email protected]> Co-authored-by: Florian Greinacher <[email protected]>
1 parent 3051799 commit bea6b3c

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

lib/resolve-config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ function shouldProxy(gitlabUrl, NO_PROXY) {
6363
ws: 80,
6464
wss: 443,
6565
};
66-
const parsedUrl = typeof gitlabUrl === 'string' ? new URL(gitlabUrl) : gitlabUrl || {};
66+
const parsedUrl =
67+
typeof gitlabUrl === 'string' && (gitlabUrl.startsWith('http://') || gitlabUrl.startsWith('https://'))
68+
? new URL(gitlabUrl)
69+
: gitlabUrl || {};
6770
let proto = parsedUrl.protocol;
6871
let hostname = parsedUrl.host;
6972
let {port} = parsedUrl;

test/resolve-config.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,52 @@ test('Returns user config via alternative environment variables', t => {
9191
);
9292
});
9393

94+
test('Returns user config via alternative environment variables with https proxy and no proto scheme set', t => {
95+
const gitlabToken = 'TOKEN';
96+
const gitlabUrl = 'host.com';
97+
const gitlabApiPathPrefix = '/api/prefix';
98+
const assets = ['file.js'];
99+
// Testing with 8080 port because HttpsProxyAgent ignores 80 port with http protocol
100+
const proxyUrl = 'http://proxy.test:8443';
101+
102+
const result = resolveConfig(
103+
{assets},
104+
{
105+
env: {
106+
GL_TOKEN: gitlabToken,
107+
GL_URL: gitlabUrl,
108+
GL_PREFIX: gitlabApiPathPrefix,
109+
HTTPS_PROXY: proxyUrl,
110+
},
111+
}
112+
);
113+
114+
t.deepEqual(result.proxy, {});
115+
});
116+
117+
test('Returns user config via alternative environment variables with http proxy and no proto scheme set', t => {
118+
const gitlabToken = 'TOKEN';
119+
const gitlabUrl = 'host.com';
120+
const gitlabApiPathPrefix = '/api/prefix';
121+
const assets = ['file.js'];
122+
// Testing with 8080 port because HttpsProxyAgent ignores 80 port with http protocol
123+
const proxyUrl = 'http://proxy.test:8080';
124+
125+
const result = resolveConfig(
126+
{assets},
127+
{
128+
env: {
129+
GL_TOKEN: gitlabToken,
130+
GL_URL: gitlabUrl,
131+
GL_PREFIX: gitlabApiPathPrefix,
132+
HTTP_PROXY: proxyUrl,
133+
},
134+
}
135+
);
136+
137+
t.deepEqual(result.proxy, {});
138+
});
139+
94140
test('Returns user config via alternative environment variables with http proxy', t => {
95141
const gitlabToken = 'TOKEN';
96142
const gitlabUrl = 'http://host.com';

0 commit comments

Comments
 (0)