Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Dec 10, 2024
1 parent cde35c5 commit 0128549
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 46 deletions.
4 changes: 2 additions & 2 deletions client/src/www/app/outline_server_repository/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ export async function parseAccessKey(accessKeyText: string): Promise<ServiceConf
}
}

export function validateAccessKey(accessKey: string) {
getAddressFromTransportConfig(accessKey);
export async function validateAccessKey(accessKey: string) {
await parseAccessKey(accessKey);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion client/src/www/app/outline_server_repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class OutlineServerRepository implements ServerRepository {
return this.serverById.get(serverId)?.server;
}

async add(accessKey: string) {
async add(accessKey: string): Promise<void> {
const alreadyAddedServer = this.serverFromAccessKey(accessKey);
if (alreadyAddedServer) {
throw new errors.ServerAlreadyAdded(alreadyAddedServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ describe('OutlineServerRepository', () => {

it('add throws on invalid access keys', async () => {
const repo = await newTestRepo(new EventQueue(), new InMemoryStorage());
expect(async () => await repo.add('ss://invalid')).toThrowError(
await expectAsync(repo.add('ss://invalid')).toBeRejectedWithError(
ServerAccessKeyInvalid
);
await expectAsync(repo.add('')).toBeRejectedWithError(
ServerAccessKeyInvalid
);
expect(async () => await repo.add('')).toThrowError(ServerAccessKeyInvalid);
});

it('getAll returns added servers', async () => {
Expand Down Expand Up @@ -307,53 +309,25 @@ describe('OutlineServerRepository', () => {

it('validates static access keys', async () => {
// Invalid access keys.
expect(async () => await config.validateAccessKey('')).toThrowError(
await expectAsync(config.validateAccessKey('')).toBeRejectedWithError(
ServerAccessKeyInvalid
);
expect(
async () => await config.validateAccessKey('ss://invalid')
).toThrowError(ServerAccessKeyInvalid);
await expectAsync(
config.validateAccessKey('ss://invalid')
).toBeRejectedWithError(ServerAccessKeyInvalid);
// IPv6 host.
expect(
async () =>
await config.validateAccessKey(
SIP002_URI.stringify(
makeConfig({
host: '2001:0:ce49:7601:e866:efff:62c3:fffe',
port: 443,
password: 'test',
method: 'chacha20-ietf-poly1305',
})
)
await config.validateAccessKey(
SIP002_URI.stringify(
makeConfig({
host: '2001:0:ce49:7601:e866:efff:62c3:fffe',
port: 443,
password: 'test',
method: 'chacha20-ietf-poly1305',
})
)
)
).toBeTruthy();
// Unsupported ciphers.
expect(
async () =>
await config.validateAccessKey(
SIP002_URI.stringify(
makeConfig({
host: '127.0.0.1',
port: 443,
password: 'test',
method: 'aes-256-ctr',
})
)
)
).toThrowError(ServerAccessKeyInvalid);
expect(
async () =>
await config.validateAccessKey(
SIP002_URI.stringify(
makeConfig({
host: '127.0.0.1',
port: 443,
password: 'test',
method: 'chacha20',
})
)
)
).toThrowError(ServerAccessKeyInvalid);
});
});

Expand Down

0 comments on commit 0128549

Please sign in to comment.