Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Nov 8, 2024
1 parent 2d52f57 commit 5b3c98c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 61 deletions.
53 changes: 53 additions & 0 deletions client/src/www/app/outline_server_repository/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import * as config from './config';
import {makeConfig, SIP002_URI} from 'ShadowsocksConfig';

describe('getAddressFromTransport', () => {
it('extracts address', () => {
Expand Down Expand Up @@ -79,3 +80,55 @@ describe('setTransportHost', () => {
expect(config.setTransportConfigHost({}, '1:2::3')).toBeUndefined();
});
});

describe('parseTunnelConfig', () => {
it('parse correctly', () => {
expect(
config.parseTunnelConfig(
'{"server": "example.com", "server_port": 443, "method": "METHOD", "password": "PASSWORD"}'
)
).toEqual({
transport: {
host: 'example.com',
port: 443,
method: 'METHOD',
password: 'PASSWORD',
},
});
});

it('parse prefix', () => {
expect(
config.parseTunnelConfig(
'{"server": "example.com", "server_port": 443, "method": "METHOD", "password": "PASSWORD", "prefix": "POST "}'
)
).toEqual({
transport: {
host: 'example.com',
port: 443,
method: 'METHOD',
password: 'PASSWORD',
prefix: 'POST ',
},
});
});

it('parse URL', () => {
const ssUrl = SIP002_URI.stringify(
makeConfig({
host: 'example.com',
port: 443,
method: 'chacha20-ietf-poly1305',
password: 'PASSWORD',
})
);
expect(config.parseTunnelConfig(ssUrl)).toEqual({
transport: {
host: 'example.com',
port: 443,
method: 'chacha20-ietf-poly1305',
password: 'PASSWORD',
},
});
});
});
21 changes: 10 additions & 11 deletions client/src/www/app/outline_server_repository/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,23 @@ export function parseTunnelConfig(
if (responseJson.prefix) {
(transport as {prefix?: string}).prefix = responseJson.prefix;
}
return {
transport,
};
return {transport};
}

/** Parses an access key string into a TunnelConfig object. */
export function staticKeyToTunnelConfig(staticKey: string): TunnelConfigJson {
try {
const config = SHADOWSOCKS_URI.parse(staticKey);
return {
transport: {
host: config.host.data,
port: config.port.data,
method: config.method.data,
password: config.password.data,
prefix: config.extra?.['prefix'],
},
const transport: TransportConfigJson = {
host: config.host.data,
port: config.port.data,
method: config.method.data,
password: config.password.data,
};
if (config.extra?.['prefix']) {
(transport as {prefix?: string}).prefix = config.extra?.['prefix'];
}
return {transport};
} catch (cause) {
throw new errors.ServerAccessKeyInvalid('Invalid static access key.', {
cause,
Expand Down
48 changes: 0 additions & 48 deletions client/src/www/app/outline_server_repository/server.spec.ts

This file was deleted.

2 changes: 0 additions & 2 deletions client/src/www/app/outline_server_repository/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import {PlatformError} from '../../model/platform_error';
import {Server, ServerType} from '../../model/server';
import {ResourceFetcher} from '../resource_fetcher';

export const TEST_ONLY = {parseTunnelConfigJson: parseTunnelConfig};

// PLEASE DON'T use this class outside of this `outline_server_repository` folder!

export class OutlineServer implements Server {
Expand Down

0 comments on commit 5b3c98c

Please sign in to comment.