@mytmpvpn/mytmpvpn-common 4.0.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/dist/.eslintrc.d.ts +0 -24
- package/dist/.eslintrc.js +0 -30
- package/dist/jest.config.d.ts +0 -6
- package/dist/jest.config.js +0 -9
- package/dist/src/errors.d.ts +0 -3
- package/dist/src/errors.js +0 -11
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.js +0 -6
- package/dist/src/models/index.d.ts +0 -2
- package/dist/src/models/index.js +0 -5
- package/dist/src/models/peanuts.d.ts +0 -13
- package/dist/src/models/peanuts.js +0 -8
- package/dist/src/models/uservpn.d.ts +0 -24
- package/dist/src/models/uservpn.js +0 -36
- package/dist/src/models/vpn.d.ts +0 -39
- package/dist/src/models/vpn.js +0 -175
- package/dist/src/utils.d.ts +0 -4
- package/dist/src/utils.js +0 -23
- package/dist/test/models.test.d.ts +0 -1
- package/dist/test/models.test.js +0 -139
package/package.json
CHANGED
package/dist/.eslintrc.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare namespace env {
|
|
2
|
-
const browser: boolean;
|
|
3
|
-
const es2021: boolean;
|
|
4
|
-
}
|
|
5
|
-
declare const _extends: string[];
|
|
6
|
-
export { _extends as extends };
|
|
7
|
-
export declare const parser: string;
|
|
8
|
-
export declare const plugins: string[];
|
|
9
|
-
export declare const root: boolean;
|
|
10
|
-
export declare const overrides: {
|
|
11
|
-
env: {
|
|
12
|
-
node: boolean;
|
|
13
|
-
};
|
|
14
|
-
files: string[];
|
|
15
|
-
parserOptions: {
|
|
16
|
-
sourceType: string;
|
|
17
|
-
};
|
|
18
|
-
}[];
|
|
19
|
-
export declare namespace parserOptions {
|
|
20
|
-
const ecmaVersion: string;
|
|
21
|
-
const project: string;
|
|
22
|
-
const sourceType: string;
|
|
23
|
-
}
|
|
24
|
-
export declare const rules: {};
|
package/dist/.eslintrc.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = {
|
|
3
|
-
env: {
|
|
4
|
-
browser: true,
|
|
5
|
-
es2021: true
|
|
6
|
-
},
|
|
7
|
-
extends: ['standard-with-typescript', 'eslint:recommended', 'plugin:@typescript-eslint/recommended'],
|
|
8
|
-
parser: '@typescript-eslint/parser',
|
|
9
|
-
plugins: ['@typescript-eslint'],
|
|
10
|
-
root: true,
|
|
11
|
-
overrides: [
|
|
12
|
-
{
|
|
13
|
-
env: {
|
|
14
|
-
node: true
|
|
15
|
-
},
|
|
16
|
-
files: [
|
|
17
|
-
'.eslintrc.{js,cjs}'
|
|
18
|
-
],
|
|
19
|
-
parserOptions: {
|
|
20
|
-
sourceType: 'script'
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
],
|
|
24
|
-
parserOptions: {
|
|
25
|
-
ecmaVersion: 'latest',
|
|
26
|
-
project: './tsconfig.json',
|
|
27
|
-
sourceType: 'module'
|
|
28
|
-
},
|
|
29
|
-
rules: {}
|
|
30
|
-
};
|
package/dist/jest.config.d.ts
DELETED
package/dist/jest.config.js
DELETED
package/dist/src/errors.d.ts
DELETED
package/dist/src/errors.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MyTmpVpnError = void 0;
|
|
4
|
-
class MyTmpVpnError extends Error {
|
|
5
|
-
constructor(msg) {
|
|
6
|
-
super(msg); // 'Error' breaks prototype chain here
|
|
7
|
-
// See: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
|
|
8
|
-
Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.MyTmpVpnError = MyTmpVpnError;
|
package/dist/src/index.d.ts
DELETED
package/dist/src/index.js
DELETED
package/dist/src/models/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
declare const PEANUTS_CONFIG: {
|
|
3
|
-
min: number;
|
|
4
|
-
max: number;
|
|
5
|
-
};
|
|
6
|
-
interface PeanutsPack {
|
|
7
|
-
name: string;
|
|
8
|
-
url: URL;
|
|
9
|
-
peanuts: number;
|
|
10
|
-
price: number;
|
|
11
|
-
description: string[];
|
|
12
|
-
}
|
|
13
|
-
export { PEANUTS_CONFIG, PeanutsPack };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import * as vpn from './vpn';
|
|
2
|
-
interface UserVpn {
|
|
3
|
-
userId: string;
|
|
4
|
-
version: number;
|
|
5
|
-
vpn: vpn.Vpn;
|
|
6
|
-
}
|
|
7
|
-
interface newUserVpnParams {
|
|
8
|
-
userId: string;
|
|
9
|
-
region: string;
|
|
10
|
-
version?: number;
|
|
11
|
-
config: vpn.VpnConfig;
|
|
12
|
-
state: vpn.VpnState;
|
|
13
|
-
}
|
|
14
|
-
interface getUserVpnFromParams {
|
|
15
|
-
userId: string;
|
|
16
|
-
vpnId: string;
|
|
17
|
-
version?: number;
|
|
18
|
-
config: vpn.VpnConfig;
|
|
19
|
-
state: vpn.VpnState;
|
|
20
|
-
}
|
|
21
|
-
declare function newUserVpn({ userId, region, version, ...rest }: newUserVpnParams): UserVpn;
|
|
22
|
-
declare function getUserVpnFrom({ userId, vpnId, version, ...rest }: getUserVpnFromParams): UserVpn;
|
|
23
|
-
declare function jsonToUserVpn(jsonString: any): UserVpn;
|
|
24
|
-
export { type UserVpn, newUserVpn, getUserVpnFrom, jsonToUserVpn };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jsonToUserVpn = exports.getUserVpnFrom = exports.newUserVpn = void 0;
|
|
4
|
-
const vpn = require("./vpn");
|
|
5
|
-
const INITIAL_VERSION = 0;
|
|
6
|
-
function newUserVpn({ userId, region, version = INITIAL_VERSION, ...rest }) {
|
|
7
|
-
return {
|
|
8
|
-
userId,
|
|
9
|
-
version,
|
|
10
|
-
vpn: vpn.newVpn(region, rest.config, rest.state)
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
exports.newUserVpn = newUserVpn;
|
|
14
|
-
function getUserVpnFrom({ userId, vpnId, version = INITIAL_VERSION, ...rest }) {
|
|
15
|
-
return {
|
|
16
|
-
userId,
|
|
17
|
-
version,
|
|
18
|
-
vpn: vpn.getVpnFrom(vpnId, rest.state, rest.config)
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
exports.getUserVpnFrom = getUserVpnFrom;
|
|
22
|
-
function jsonToUserVpn(jsonString) {
|
|
23
|
-
const parsed = JSON.parse(jsonString, (key, value) => {
|
|
24
|
-
if (key === 'createdAt') {
|
|
25
|
-
return new Date(value);
|
|
26
|
-
}
|
|
27
|
-
return value;
|
|
28
|
-
});
|
|
29
|
-
const result = {
|
|
30
|
-
userId: parsed.userId,
|
|
31
|
-
version: parsed.version,
|
|
32
|
-
vpn: parsed.vpn
|
|
33
|
-
};
|
|
34
|
-
return parsed;
|
|
35
|
-
}
|
|
36
|
-
exports.jsonToUserVpn = jsonToUserVpn;
|
package/dist/src/models/vpn.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
declare enum VpnState {
|
|
2
|
-
Failed = "Failed",
|
|
3
|
-
Creating = "Creating",
|
|
4
|
-
Created = "Created",
|
|
5
|
-
Provisioning = "Provisioning",
|
|
6
|
-
Paused = "Paused",
|
|
7
|
-
Running = "Running",
|
|
8
|
-
Deprovisioning = "Deprovisioning",
|
|
9
|
-
Deleted = "Deleted"
|
|
10
|
-
}
|
|
11
|
-
declare function rank(state: VpnState): number;
|
|
12
|
-
declare enum VpnType {
|
|
13
|
-
WireGuard = "wireguard"
|
|
14
|
-
}
|
|
15
|
-
declare const MIN_DELETE_AFTER: number;
|
|
16
|
-
declare const MAX_DELETE_AFTER: number;
|
|
17
|
-
interface VpnConfig {
|
|
18
|
-
type: VpnType;
|
|
19
|
-
maxPeanuts: number;
|
|
20
|
-
deleteAfter?: number;
|
|
21
|
-
}
|
|
22
|
-
interface VpnMetrics {
|
|
23
|
-
duration: number;
|
|
24
|
-
bytes: number;
|
|
25
|
-
peanuts: number;
|
|
26
|
-
}
|
|
27
|
-
interface Vpn {
|
|
28
|
-
vpnId: string;
|
|
29
|
-
createdAt: Date;
|
|
30
|
-
region: string;
|
|
31
|
-
config: VpnConfig;
|
|
32
|
-
state: VpnState;
|
|
33
|
-
}
|
|
34
|
-
declare function getVpnConfigTypes(): VpnType[];
|
|
35
|
-
declare function throwIfNotValidDeleteAfter(deleteAfter: number | undefined): void;
|
|
36
|
-
declare function newVpn(region: string, config: VpnConfig, state: VpnState): Vpn;
|
|
37
|
-
declare function getVpnFrom(vpnId: string, state: VpnState, config: VpnConfig): Vpn;
|
|
38
|
-
declare function vpnIdToWgFileName(vpnId: string): string;
|
|
39
|
-
export { VpnState, type VpnMetrics, VpnType, type VpnConfig, type Vpn, rank, newVpn, getVpnFrom, getVpnConfigTypes, vpnIdToWgFileName, MIN_DELETE_AFTER, MAX_DELETE_AFTER, throwIfNotValidDeleteAfter };
|
package/dist/src/models/vpn.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.throwIfNotValidDeleteAfter = exports.MAX_DELETE_AFTER = exports.MIN_DELETE_AFTER = exports.vpnIdToWgFileName = exports.getVpnConfigTypes = exports.getVpnFrom = exports.newVpn = exports.rank = exports.VpnType = exports.VpnState = void 0;
|
|
4
|
-
const errors_1 = require("../errors");
|
|
5
|
-
var VpnState;
|
|
6
|
-
(function (VpnState) {
|
|
7
|
-
VpnState["Failed"] = "Failed";
|
|
8
|
-
VpnState["Creating"] = "Creating";
|
|
9
|
-
VpnState["Created"] = "Created";
|
|
10
|
-
VpnState["Provisioning"] = "Provisioning";
|
|
11
|
-
VpnState["Paused"] = "Paused";
|
|
12
|
-
VpnState["Running"] = "Running";
|
|
13
|
-
VpnState["Deprovisioning"] = "Deprovisioning";
|
|
14
|
-
VpnState["Deleted"] = "Deleted";
|
|
15
|
-
})(VpnState || (VpnState = {}));
|
|
16
|
-
exports.VpnState = VpnState;
|
|
17
|
-
const vpnStateRank = Object.values(VpnState);
|
|
18
|
-
function rank(state) {
|
|
19
|
-
return vpnStateRank.indexOf(state);
|
|
20
|
-
}
|
|
21
|
-
exports.rank = rank;
|
|
22
|
-
var VpnType;
|
|
23
|
-
(function (VpnType) {
|
|
24
|
-
VpnType["WireGuard"] = "wireguard";
|
|
25
|
-
})(VpnType || (VpnType = {}));
|
|
26
|
-
exports.VpnType = VpnType;
|
|
27
|
-
const MIN_DELETE_AFTER = 5 * 60; // Minimum is 5 minutes
|
|
28
|
-
exports.MIN_DELETE_AFTER = MIN_DELETE_AFTER;
|
|
29
|
-
const MAX_DELETE_AFTER = 24 * 60 * 60; // Maximum is 24 hours
|
|
30
|
-
exports.MAX_DELETE_AFTER = MAX_DELETE_AFTER;
|
|
31
|
-
function getVpnConfigTypes() {
|
|
32
|
-
return Object.values(VpnType).filter((item) => {
|
|
33
|
-
return isNaN(Number(item));
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
exports.getVpnConfigTypes = getVpnConfigTypes;
|
|
37
|
-
function throwIfNotValidVpnId(vpnId) {
|
|
38
|
-
// e.g: YYYYMMDDHHmmssmss@az-test-7
|
|
39
|
-
if (!/\d{4}[01]\d[0-3]\d[0-2]\d[0-5]\d[0-5]\d\d{3}@[a-z]{2}-[a-z]+-\d/.test(vpnId)) {
|
|
40
|
-
throw new errors_1.MyTmpVpnError(`Incorrect vpnId: \'${vpnId}\'`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function throwIfNotValidDeleteAfter(deleteAfter) {
|
|
44
|
-
if (deleteAfter === undefined) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (isNaN(deleteAfter)) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (!isFinite(deleteAfter)) {
|
|
51
|
-
throw new errors_1.MyTmpVpnError(`deleteAfter must be finite: ${deleteAfter}`);
|
|
52
|
-
}
|
|
53
|
-
if (deleteAfter < MIN_DELETE_AFTER) {
|
|
54
|
-
throw new errors_1.MyTmpVpnError(`deleteAfter must be greater than ${MIN_DELETE_AFTER}: ${deleteAfter}`);
|
|
55
|
-
}
|
|
56
|
-
if (deleteAfter > MAX_DELETE_AFTER) {
|
|
57
|
-
throw new errors_1.MyTmpVpnError(`deleteAfter must be lesser than ${MAX_DELETE_AFTER}: ${deleteAfter}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.throwIfNotValidDeleteAfter = throwIfNotValidDeleteAfter;
|
|
61
|
-
function newVpn(region, config, state) {
|
|
62
|
-
// e.g: ap-northeast-3
|
|
63
|
-
if (!/[a-z]{2}-[a-z]+-[1-9]+/.test(region)) {
|
|
64
|
-
throw new errors_1.MyTmpVpnError(`Incorrect region: \'${region}\'`);
|
|
65
|
-
}
|
|
66
|
-
const createdAt = new Date();
|
|
67
|
-
const vpnId = `${dateToId(createdAt)}@${region}`;
|
|
68
|
-
// Assert we will be able to deserialize later on...
|
|
69
|
-
throwIfNotValidVpnId(vpnId);
|
|
70
|
-
throwIfNotValidDeleteAfter(config.deleteAfter);
|
|
71
|
-
return {
|
|
72
|
-
vpnId,
|
|
73
|
-
createdAt,
|
|
74
|
-
region,
|
|
75
|
-
config,
|
|
76
|
-
state
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
exports.newVpn = newVpn;
|
|
80
|
-
function getVpnFrom(vpnId, state, config) {
|
|
81
|
-
throwIfNotValidVpnId(vpnId);
|
|
82
|
-
throwIfNotValidDeleteAfter(config.deleteAfter);
|
|
83
|
-
const tokens = vpnId.split('@');
|
|
84
|
-
if (tokens.length !== 2) {
|
|
85
|
-
throw new errors_1.MyTmpVpnError(`Incorrect vpnId: ${vpnId}`);
|
|
86
|
-
}
|
|
87
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
88
|
-
const createdAt = idToDate(tokens[0]);
|
|
89
|
-
const region = tokens[1];
|
|
90
|
-
/* eslint-enable @typescript-eslint/no-non-null-assertion */
|
|
91
|
-
return {
|
|
92
|
-
vpnId,
|
|
93
|
-
createdAt,
|
|
94
|
-
region,
|
|
95
|
-
config,
|
|
96
|
-
state
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
exports.getVpnFrom = getVpnFrom;
|
|
100
|
-
// Using a date from an id is convenient for debugging.
|
|
101
|
-
// We can't use Date.toISOString() because some characters are forbidden
|
|
102
|
-
// E.g: SFn refuse the ':'
|
|
103
|
-
// So we need convertor back and forth
|
|
104
|
-
function dateToId(date) {
|
|
105
|
-
// YYYY-MM-DDTHH:mm:ss.uuuZ -> YYYYMMDDHHmmssuuu
|
|
106
|
-
return date.toISOString().replace(/[^\d]/g, '');
|
|
107
|
-
}
|
|
108
|
-
function idToDate(id) {
|
|
109
|
-
// YYYYMMDDHHmmssuuu -> YYYY-MM-DDTHH:mm:ss.uuuZ
|
|
110
|
-
const year = id.substring(0, 4);
|
|
111
|
-
const month = id.substring(4, 6);
|
|
112
|
-
const day = id.substring(6, 8);
|
|
113
|
-
const hour = id.substring(8, 10);
|
|
114
|
-
const minute = id.substring(10, 12);
|
|
115
|
-
const second = id.substring(12, 14);
|
|
116
|
-
const millis = id.substring(14);
|
|
117
|
-
return new Date(`${year}-${month}-${day}T${hour}:${minute}:${second}.${millis}Z`);
|
|
118
|
-
}
|
|
119
|
-
// The WireGuard Mobile Application has requirements for the wireguard configuration file:
|
|
120
|
-
// 1. must have extension '.conf'
|
|
121
|
-
// 2. file name must match the following regexp: "[a-zA-Z0-9_=+.-]{1,15}")
|
|
122
|
-
// https://git.zx2c4.com/wireguard-android/tree/tunnel/src/main/java/com/wireguard/android/backend/Tunnel.java#n19
|
|
123
|
-
// This function is to transform from vpnIn to Wireguard mobile application requirements
|
|
124
|
-
function vpnIdToWgFileName(vpnId) {
|
|
125
|
-
throwIfNotValidVpnId(vpnId);
|
|
126
|
-
// The vpnId is made of YYYYMMDDHHmmssmss@region
|
|
127
|
-
// Let's keep it simple: vpn is mostly temporary, so keeping
|
|
128
|
-
// the year is useless.
|
|
129
|
-
// Also the milliseconds are useless.
|
|
130
|
-
// Finally, the region itself is of the following format: ap-northeast-3
|
|
131
|
-
// We can compressing with something like:
|
|
132
|
-
// MMDDHHmmssapne3.conf
|
|
133
|
-
const ddhhmmss = vpnId.substring(4, 14);
|
|
134
|
-
const seps = vpnId.substring(18).split(/-/);
|
|
135
|
-
const ccld = seps[0];
|
|
136
|
-
let location;
|
|
137
|
-
switch (seps[1]) {
|
|
138
|
-
case 'north':
|
|
139
|
-
location = 'n';
|
|
140
|
-
break;
|
|
141
|
-
case 'northeast':
|
|
142
|
-
location = 'ne';
|
|
143
|
-
break;
|
|
144
|
-
case 'east':
|
|
145
|
-
location = 'e';
|
|
146
|
-
break;
|
|
147
|
-
case 'southeast':
|
|
148
|
-
location = 'se';
|
|
149
|
-
break;
|
|
150
|
-
case 'south':
|
|
151
|
-
location = 's';
|
|
152
|
-
break;
|
|
153
|
-
case 'southwest':
|
|
154
|
-
location = 'sw';
|
|
155
|
-
break;
|
|
156
|
-
case 'west':
|
|
157
|
-
location = 'w';
|
|
158
|
-
break;
|
|
159
|
-
case 'northwest':
|
|
160
|
-
location = 'nw';
|
|
161
|
-
break;
|
|
162
|
-
case 'central':
|
|
163
|
-
location = 'c';
|
|
164
|
-
break;
|
|
165
|
-
default:
|
|
166
|
-
'';
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
const number = seps[2];
|
|
170
|
-
// Let's make sure the end file is of 15 char max
|
|
171
|
-
const result = `${ddhhmmss}${ccld}${location}${number}`.substring(0, 15);
|
|
172
|
-
console.log(`Transforming ${vpnId} to ${result}`);
|
|
173
|
-
return result;
|
|
174
|
-
}
|
|
175
|
-
exports.vpnIdToWgFileName = vpnIdToWgFileName;
|
package/dist/src/utils.d.ts
DELETED
package/dist/src/utils.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sleep = exports.choose = exports.getFromEnvOrThrow = void 0;
|
|
4
|
-
const log = require("loglevel");
|
|
5
|
-
function getFromEnvOrThrow(env) {
|
|
6
|
-
const result = process.env[env];
|
|
7
|
-
if (result === null || result === undefined || result.trim() === '') {
|
|
8
|
-
throw new Error(`${env} unset in environment!`);
|
|
9
|
-
}
|
|
10
|
-
log.debug(`Using ${env} = ${result}`);
|
|
11
|
-
return result;
|
|
12
|
-
}
|
|
13
|
-
exports.getFromEnvOrThrow = getFromEnvOrThrow;
|
|
14
|
-
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
15
|
-
function choose(choices) {
|
|
16
|
-
const index = Math.floor(Math.random() * choices.length);
|
|
17
|
-
return choices[index];
|
|
18
|
-
}
|
|
19
|
-
exports.choose = choose;
|
|
20
|
-
async function sleep(millis) {
|
|
21
|
-
await new Promise(resolve => setTimeout(resolve, millis));
|
|
22
|
-
}
|
|
23
|
-
exports.sleep = sleep;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test/models.test.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const uservpn_1 = require("../src/models/uservpn");
|
|
4
|
-
const errors_1 = require("../src/errors");
|
|
5
|
-
const vpn_1 = require("../src/models/vpn");
|
|
6
|
-
describe('Testing VpnState', () => {
|
|
7
|
-
it('should check that all VpnState are ordered properly', async () => {
|
|
8
|
-
expect((0, vpn_1.rank)(vpn_1.VpnState.Creating) <= (0, vpn_1.rank)(vpn_1.VpnState.Created)).toBe(true);
|
|
9
|
-
expect((0, vpn_1.rank)(vpn_1.VpnState.Created) <= (0, vpn_1.rank)(vpn_1.VpnState.Provisioning)).toBe(true);
|
|
10
|
-
expect((0, vpn_1.rank)(vpn_1.VpnState.Provisioning) <= (0, vpn_1.rank)(vpn_1.VpnState.Running)).toBe(true);
|
|
11
|
-
expect((0, vpn_1.rank)(vpn_1.VpnState.Paused) <= (0, vpn_1.rank)(vpn_1.VpnState.Running)).toBe(true);
|
|
12
|
-
expect((0, vpn_1.rank)(vpn_1.VpnState.Running) <= (0, vpn_1.rank)(vpn_1.VpnState.Deprovisioning)).toBe(true);
|
|
13
|
-
expect((0, vpn_1.rank)(vpn_1.VpnState.Deprovisioning) <= (0, vpn_1.rank)(vpn_1.VpnState.Deleted)).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
describe('Testing Vpn constructors', () => {
|
|
17
|
-
it('Should shout when regions is empty', async () => {
|
|
18
|
-
expect(() => (0, vpn_1.newVpn)('', { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard }, vpn_1.VpnState.Created))
|
|
19
|
-
.toThrow(new errors_1.MyTmpVpnError("Incorrect region: \'\'"));
|
|
20
|
-
});
|
|
21
|
-
it('Should shout when regions is bad format', async () => {
|
|
22
|
-
expect(() => (0, vpn_1.newVpn)('foo', { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard }, vpn_1.VpnState.Created))
|
|
23
|
-
.toThrow(new errors_1.MyTmpVpnError("Incorrect region: \'foo\'"));
|
|
24
|
-
});
|
|
25
|
-
it('Should create vpn with all mandatory fields set', async () => {
|
|
26
|
-
const vpn = (0, vpn_1.newVpn)('az-test-7', { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard }, vpn_1.VpnState.Created);
|
|
27
|
-
expect(vpn.createdAt).toBeDefined();
|
|
28
|
-
expect(vpn.region).toEqual('az-test-7');
|
|
29
|
-
expect(vpn.state).toEqual(vpn_1.VpnState.Created);
|
|
30
|
-
expect(vpn.config).toEqual({ maxPeanuts: -1, type: vpn_1.VpnType.WireGuard });
|
|
31
|
-
expect(vpn.vpnId).toBeDefined();
|
|
32
|
-
});
|
|
33
|
-
it('Should create vpn with optional fields set', async () => {
|
|
34
|
-
const deleteAfter = vpn_1.MIN_DELETE_AFTER;
|
|
35
|
-
const vpn = (0, vpn_1.newVpn)('az-test-7', {
|
|
36
|
-
maxPeanuts: -1,
|
|
37
|
-
type: vpn_1.VpnType.WireGuard,
|
|
38
|
-
deleteAfter: deleteAfter
|
|
39
|
-
}, vpn_1.VpnState.Created);
|
|
40
|
-
expect(vpn.createdAt).toBeDefined();
|
|
41
|
-
expect(vpn.region).toEqual('az-test-7');
|
|
42
|
-
expect(vpn.state).toEqual(vpn_1.VpnState.Created);
|
|
43
|
-
expect(vpn.config).toEqual({ maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, deleteAfter: deleteAfter });
|
|
44
|
-
expect(vpn.vpnId).toBeDefined();
|
|
45
|
-
});
|
|
46
|
-
it('Should create vpn with deleteAfter set to NaN', async () => {
|
|
47
|
-
const deleteAfter = Number.NaN;
|
|
48
|
-
const vpn = (0, vpn_1.newVpn)('az-test-7', {
|
|
49
|
-
maxPeanuts: -1,
|
|
50
|
-
type: vpn_1.VpnType.WireGuard,
|
|
51
|
-
deleteAfter: deleteAfter
|
|
52
|
-
}, vpn_1.VpnState.Created);
|
|
53
|
-
expect(vpn.createdAt).toBeDefined();
|
|
54
|
-
expect(vpn.region).toEqual('az-test-7');
|
|
55
|
-
expect(vpn.state).toEqual(vpn_1.VpnState.Created);
|
|
56
|
-
expect(vpn.config).toEqual({ maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, deleteAfter: deleteAfter });
|
|
57
|
-
expect(vpn.vpnId).toBeDefined();
|
|
58
|
-
});
|
|
59
|
-
it('Should deserialize a vpn with all mandatory fields set', async () => {
|
|
60
|
-
const deleteAfter = vpn_1.MIN_DELETE_AFTER;
|
|
61
|
-
const vpn = (0, vpn_1.getVpnFrom)('20030902012345678@az-test-7', vpn_1.VpnState.Created, { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, deleteAfter: deleteAfter });
|
|
62
|
-
expect(vpn.createdAt).toEqual(new Date('2003-09-02T01:23:45.678Z'));
|
|
63
|
-
expect(vpn.region).toEqual('az-test-7');
|
|
64
|
-
expect(vpn.state).toEqual(vpn_1.VpnState.Created);
|
|
65
|
-
expect(vpn.config).toEqual({ maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, deleteAfter: deleteAfter });
|
|
66
|
-
expect(vpn.vpnId).toBeDefined();
|
|
67
|
-
});
|
|
68
|
-
it('Should deserialize a vpn with deleteAfter set to NaN', async () => {
|
|
69
|
-
const deleteAfter = Number.NaN;
|
|
70
|
-
const vpn = (0, vpn_1.getVpnFrom)('20030902012345678@az-test-7', vpn_1.VpnState.Created, { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, deleteAfter: deleteAfter });
|
|
71
|
-
expect(vpn.createdAt).toEqual(new Date('2003-09-02T01:23:45.678Z'));
|
|
72
|
-
expect(vpn.region).toEqual('az-test-7');
|
|
73
|
-
expect(vpn.state).toEqual(vpn_1.VpnState.Created);
|
|
74
|
-
expect(vpn.config).toEqual({ maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, deleteAfter: deleteAfter });
|
|
75
|
-
expect(vpn.vpnId).toBeDefined();
|
|
76
|
-
});
|
|
77
|
-
it('Should deserialize a json vpn with all fields set', async () => {
|
|
78
|
-
const originalVpn = (0, uservpn_1.newUserVpn)({
|
|
79
|
-
userId: 'myId',
|
|
80
|
-
region: 'az-test-7',
|
|
81
|
-
version: 1,
|
|
82
|
-
config: {
|
|
83
|
-
maxPeanuts: -1,
|
|
84
|
-
type: vpn_1.VpnType.WireGuard,
|
|
85
|
-
deleteAfter: vpn_1.MIN_DELETE_AFTER
|
|
86
|
-
},
|
|
87
|
-
state: vpn_1.VpnState.Created,
|
|
88
|
-
});
|
|
89
|
-
const jsonString = JSON.stringify(originalVpn);
|
|
90
|
-
const userVpn = (0, uservpn_1.jsonToUserVpn)(jsonString);
|
|
91
|
-
expect(userVpn).toEqual(originalVpn);
|
|
92
|
-
});
|
|
93
|
-
it('Should shout when vpnId is empty', async () => {
|
|
94
|
-
expect(() => (0, vpn_1.getVpnFrom)('', vpn_1.VpnState.Created, { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard }))
|
|
95
|
-
.toThrow(new errors_1.MyTmpVpnError("Incorrect vpnId: \'\'"));
|
|
96
|
-
});
|
|
97
|
-
it('Should shout when vpnId has bad format', async () => {
|
|
98
|
-
expect(() => (0, vpn_1.getVpnFrom)('foo', vpn_1.VpnState.Created, { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard }))
|
|
99
|
-
.toThrow(new errors_1.MyTmpVpnError("Incorrect vpnId: \'foo\'"));
|
|
100
|
-
});
|
|
101
|
-
it('Should shout when vpnId does not hold a region in good format', async () => {
|
|
102
|
-
expect(() => (0, vpn_1.getVpnFrom)('20030902012345678@test', vpn_1.VpnState.Created, { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard }))
|
|
103
|
-
.toThrow(new errors_1.MyTmpVpnError("Incorrect vpnId: \'20030902012345678@test\'"));
|
|
104
|
-
});
|
|
105
|
-
it('Should shout when deleteAfter is lower than MIN', async () => {
|
|
106
|
-
const wrongDeleteAfter = vpn_1.MIN_DELETE_AFTER - 1;
|
|
107
|
-
expect(() => (0, vpn_1.newVpn)('az-test-7', { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, deleteAfter: wrongDeleteAfter }, vpn_1.VpnState.Created))
|
|
108
|
-
.toThrow(new errors_1.MyTmpVpnError(`deleteAfter must be greater than ${vpn_1.MIN_DELETE_AFTER}: ${wrongDeleteAfter}`));
|
|
109
|
-
});
|
|
110
|
-
it('Should shout when deleteAfter is greater than MAX', async () => {
|
|
111
|
-
const wrongDeleteAfter = vpn_1.MAX_DELETE_AFTER + 1;
|
|
112
|
-
expect(() => (0, vpn_1.newVpn)('az-test-7', { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, deleteAfter: wrongDeleteAfter }, vpn_1.VpnState.Created))
|
|
113
|
-
.toThrow(new errors_1.MyTmpVpnError(`deleteAfter must be lesser than ${vpn_1.MAX_DELETE_AFTER}: ${wrongDeleteAfter}`));
|
|
114
|
-
});
|
|
115
|
-
it('Should shout when deleteAfter is positive infinity', async () => {
|
|
116
|
-
const wrongdeleteAfter = Number.POSITIVE_INFINITY;
|
|
117
|
-
expect(() => (0, vpn_1.newVpn)('az-test-7', { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, deleteAfter: wrongdeleteAfter }, vpn_1.VpnState.Created))
|
|
118
|
-
.toThrow(new errors_1.MyTmpVpnError(`deleteAfter must be finite: ${wrongdeleteAfter}`));
|
|
119
|
-
});
|
|
120
|
-
it('Should shout when deleteAfter is negative infinity', async () => {
|
|
121
|
-
const wrongdeleteAfter = Number.NEGATIVE_INFINITY;
|
|
122
|
-
expect(() => (0, vpn_1.newVpn)('az-test-7', { maxPeanuts: -1, type: vpn_1.VpnType.WireGuard, deleteAfter: wrongdeleteAfter }, vpn_1.VpnState.Created))
|
|
123
|
-
.toThrow(new errors_1.MyTmpVpnError(`deleteAfter must be finite: ${wrongdeleteAfter}`));
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
describe('Testing vpnId to Wireguard file name functions ', () => {
|
|
127
|
-
it('Should shout when vpnId is empty', async () => {
|
|
128
|
-
expect(() => (0, vpn_1.vpnIdToWgFileName)(''))
|
|
129
|
-
.toThrow(new errors_1.MyTmpVpnError("Incorrect vpnId: \'\'"));
|
|
130
|
-
});
|
|
131
|
-
it('Should shout when vpnId is bad format', async () => {
|
|
132
|
-
expect(() => (0, vpn_1.vpnIdToWgFileName)('foo'))
|
|
133
|
-
.toThrow(new errors_1.MyTmpVpnError("Incorrect vpnId: \'foo\'"));
|
|
134
|
-
});
|
|
135
|
-
it('Should shout when region has bad format', async () => {
|
|
136
|
-
expect(() => (0, vpn_1.vpnIdToWgFileName)('20030902012345678@test'))
|
|
137
|
-
.toThrow(new errors_1.MyTmpVpnError("Incorrect vpnId: \'20030902012345678@test\'"));
|
|
138
|
-
});
|
|
139
|
-
});
|