Skip to content

Commit

Permalink
Merge branch 'master' into daniellacosse/tunneltime/move_metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellacosse authored Nov 14, 2024
2 parents 2a6076d + 49bf053 commit 23bf19e
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 186 deletions.
2 changes: 1 addition & 1 deletion client/electron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ async function createVpnTunnel(
// because startVpn will add a routing table entry that prefixed with this
// host (e.g. "<host>/32"), therefore <host> must be an IP address.
// TODO: make sure we resolve it in the native code
const host = config.getHostFromTransportConfig(tunnelConfig.transport);
const host = tunnelConfig.firstHop.host;
if (!host) {
throw new errors.IllegalServerConfiguration('host is missing');
}
Expand Down
9 changes: 8 additions & 1 deletion client/src/www/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,14 @@ export class App {

this.eventQueue.startPublishing();

this.rootEl.$.addServerView.validateAccessKey = config.validateAccessKey;
this.rootEl.$.addServerView.isValidAccessKey = (accessKey: string) => {
try {
config.parseAccessKey(accessKey);
return true;
} catch {
return false;
}
};
if (!this.arePrivacyTermsAcked()) {
this.displayPrivacyView();
} else if (this.rootEl.$.serversView.shouldShowZeroState) {
Expand Down
112 changes: 79 additions & 33 deletions client/src/www/app/outline_server_repository/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,27 @@ import * as config from './config';
describe('getAddressFromTransport', () => {
it('extracts address', () => {
expect(
config.getAddressFromTransportConfig({host: 'example.com', port: '443'})
).toEqual('example.com:443');
config.TEST_ONLY.getAddressFromTransportConfig({
host: 'example.com',
port: 443,
})
).toEqual({host: 'example.com', port: 443});
expect(
config.getAddressFromTransportConfig({host: '1:2::3', port: '443'})
).toEqual('[1:2::3]:443');
expect(config.getAddressFromTransportConfig({host: 'example.com'})).toEqual(
'example.com'
);
expect(config.getAddressFromTransportConfig({host: '1:2::3'})).toEqual(
'1:2::3'
);
});

it('fails on invalid config', () => {
expect(config.getAddressFromTransportConfig({})).toBeUndefined();
});
});

describe('getHostFromTransport', () => {
it('extracts host', () => {
config.TEST_ONLY.getAddressFromTransportConfig({
host: '1:2::3',
port: 443,
})
).toEqual({host: '1:2::3', port: 443});
expect(
config.getHostFromTransportConfig({host: 'example.com', port: '443'})
).toEqual('example.com');
config.TEST_ONLY.getAddressFromTransportConfig({host: 'example.com'})
).toEqual({host: 'example.com', port: undefined});
expect(
config.getHostFromTransportConfig({host: '1:2::3', port: '443'})
).toEqual('1:2::3');
config.TEST_ONLY.getAddressFromTransportConfig({host: '1:2::3'})
).toEqual({host: '1:2::3', port: undefined});
});

it('fails on invalid config', () => {
expect(config.getHostFromTransportConfig({})).toBeUndefined();
expect(config.TEST_ONLY.getAddressFromTransportConfig({})).toBeUndefined();
});
});

Expand All @@ -57,24 +48,24 @@ describe('setTransportHost', () => {
expect(
JSON.stringify(
config.setTransportConfigHost(
{host: 'example.com', port: '443'},
{host: 'example.com', port: 443},
'1.2.3.4'
)
)
).toEqual('{"host":"1.2.3.4","port":"443"}');
).toEqual('{"host":"1.2.3.4","port":443}');
expect(
JSON.stringify(
config.setTransportConfigHost(
{host: 'example.com', port: '443'},
{host: 'example.com', port: 443},
'1:2::3'
)
)
).toEqual('{"host":"1:2::3","port":"443"}');
).toEqual('{"host":"1:2::3","port":443}');
expect(
JSON.stringify(
config.setTransportConfigHost({host: '1.2.3.4', port: '443'}, '1:2::3')
config.setTransportConfigHost({host: '1.2.3.4', port: 443}, '1:2::3')
)
).toEqual('{"host":"1:2::3","port":"443"}');
).toEqual('{"host":"1:2::3","port":443}');
});

it('fails on invalid config', () => {
Expand All @@ -83,12 +74,16 @@ describe('setTransportHost', () => {
});

describe('parseTunnelConfig', () => {
it('parse correctly', () => {
it('parses correctly', () => {
expect(
config.parseTunnelConfig(
'{"server": "example.com", "server_port": 443, "method": "METHOD", "password": "PASSWORD"}'
)
).toEqual({
firstHop: {
host: 'example.com',
port: 443,
},
transport: {
host: 'example.com',
port: 443,
Expand All @@ -98,12 +93,16 @@ describe('parseTunnelConfig', () => {
});
});

it('parse prefix', () => {
it('parses prefix', () => {
expect(
config.parseTunnelConfig(
'{"server": "example.com", "server_port": 443, "method": "METHOD", "password": "PASSWORD", "prefix": "POST "}'
)
).toEqual({
firstHop: {
host: 'example.com',
port: 443,
},
transport: {
host: 'example.com',
port: 443,
Expand All @@ -114,7 +113,7 @@ describe('parseTunnelConfig', () => {
});
});

it('parse URL', () => {
it('parses URL', () => {
const ssUrl = SIP002_URI.stringify(
makeConfig({
host: 'example.com',
Expand All @@ -124,6 +123,10 @@ describe('parseTunnelConfig', () => {
})
);
expect(config.parseTunnelConfig(ssUrl)).toEqual({
firstHop: {
host: 'example.com',
port: 443,
},
transport: {
host: 'example.com',
port: 443,
Expand All @@ -132,4 +135,47 @@ describe('parseTunnelConfig', () => {
},
});
});

it('parses URL with blanks', () => {
const ssUrl = SIP002_URI.stringify(
makeConfig({
host: 'example.com',
port: 443,
method: 'chacha20-ietf-poly1305',
password: 'PASSWORD',
})
);
expect(config.parseTunnelConfig(` ${ssUrl} \n\n\n`)).toEqual({
firstHop: {
host: 'example.com',
port: 443,
},
transport: {
host: 'example.com',
port: 443,
method: 'chacha20-ietf-poly1305',
password: 'PASSWORD',
},
});
});
});

describe('serviceNameFromAccessKey', () => {
it('extracts name from ss:// key', () => {
expect(
config.TEST_ONLY.serviceNameFromAccessKey('ss://anything#My%20Server')
).toEqual('My Server');
});
it('extracts name from ssconf:// key', () => {
expect(
config.TEST_ONLY.serviceNameFromAccessKey('ssconf://anything#My%20Server')
).toEqual('My Server');
});
it('ignores parameters', () => {
expect(
config.TEST_ONLY.serviceNameFromAccessKey(
'ss://anything#foo=bar&My%20Server&baz=boo'
)
).toEqual('My Server');
});
});
Loading

0 comments on commit 23bf19e

Please sign in to comment.