Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
with:
fetch-depth: 0

- name: Setup Deno v2.7.13
- name: Setup Deno v2.7.14
uses: denoland/setup-deno@v2
with:
deno-version: v2.7.13
deno-version: v2.7.14

- name: Setup LCOV
run: sudo apt install -y lcov
Expand All @@ -35,7 +35,7 @@ jobs:
run: deno task cover

- name: SonarCloud Scan
uses: sonarsource/sonarqube-scan-action@v7.0.0
uses: sonarsource/sonarqube-scan-action@v8.0.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN != ''
Expand All @@ -45,7 +45,7 @@ jobs:
strategy:
fail-fast: false
matrix:
deno-version: [v1.46.3, v2.7.13]
deno-version: [v1.46.3, v2.7.14]
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
ref: ${{ steps.pr.outputs.head_sha }}
fetch-depth: 0

- name: Setup Deno v2.7.13
- name: Setup Deno v2.7.14
uses: denoland/setup-deno@v2
with:
deno-version: v2.7.13
deno-version: v2.7.14

- name: Setup LCOV
run: sudo apt install -y lcov
Expand All @@ -51,7 +51,7 @@ jobs:
run: deno task cover

- name: SonarCloud Scan
uses: sonarsource/sonarqube-scan-action@v7.0.0
uses: sonarsource/sonarqube-scan-action@v8.0.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN != ''
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ Client.buildContext({
silentMode: '5m', // Fallback timeout
restrictRelay: true, // Relay restrictions in local mode
regexSafe: true, // Prevent reDOS attacks
certPath: './certs/ca.pem' // SSL certificate path
certPath: './certs/ca.pem', // SSL certificate path
remoteTimeout: 2000 // Remote Criteria API timeout (milliseconds)
});
```

Expand All @@ -153,6 +154,7 @@ Client.buildContext({
| `regexMaxBlackList` | number | Max cached regex failures |
| `regexMaxTimeLimit` | number | Regex timeout in milliseconds |
| `certPath` | string | Path to SSL certificate file |
| `remoteTimeout` | number | Remote Criteria API timeout in milliseconds |

> **⚠️ Note on regexSafe**: This feature protects against reDOS attacks but uses Web Workers, which are incompatible with compiled executables.

Expand Down
11 changes: 7 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export class Client {
logger: util.get(options?.logger, DEFAULT_LOGGER),
});

// Initialize Auth
Auth.init(this._context);

if (options) {
Client.buildOptions(options);
}

// Initialize Auth
Auth.init(this._context);
}

private static buildOptions(options: SwitcherOptions) {
Expand All @@ -84,6 +84,9 @@ export class Client {
[SWITCHER_OPTIONS.SILENT_MODE]: () => {
if (options.silentMode) this._initSilentMode(options.silentMode);
},
[SWITCHER_OPTIONS.REMOTE_TIMEOUT]: () => {
if (options.remoteTimeout) remote.setRemoteTimeout(options.remoteTimeout);
},
[SWITCHER_OPTIONS.RESTRICT_RELAY]: () => {
GlobalOptions.updateOptions({ restrictRelay: options.restrictRelay });
},
Expand Down Expand Up @@ -371,7 +374,7 @@ export class Client {
/**
* Enable/Disable test mode.
*
* It prevents from watching Snapshots that may hold process
* It prevents subprocess to run during tests such as snapshot watcher
*/
static testMode(testEnabled: boolean = true): void {
Client._testEnabled = testEnabled;
Expand Down
5 changes: 1 addition & 4 deletions src/lib/bypasser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ export default class Bypasser {
* @param key
*/
static assume(key: string): Key {
const existentKey = this.searchBypassed(key);
if (existentKey) {
return existentKey;
}
Bypasser.forget(key);

const keyBypassed = new Key(key);
bypassedKeys.push(keyBypassed);
Expand Down
1 change: 1 addition & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export enum SWITCHER_OPTIONS {
REGEX_MAX_BLACK_LIST = 'regexMaxBlackList',
REGEX_MAX_TIME_LIMIT = 'regexMaxTimeLimit',
CERT_PATH = 'certPath',
REMOTE_TIMEOUT = 'remoteTimeout',
}
6 changes: 6 additions & 0 deletions src/lib/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as util from './utils/index.ts';
import { GlobalAuth } from './globals/globalAuth.ts';

let httpClient: Deno.HttpClient;
let remoteTimeout: number = 2 * 1000;

const getHeader = (token: string | undefined) => {
return {
Expand All @@ -20,6 +21,10 @@ export const setCerts = (certPath: string) => {
});
};

export const setRemoteTimeout = (timeout: number) => {
remoteTimeout = timeout;
};

export const destroyHttpClient = () => {
if (httpClient) {
httpClient.close();
Expand Down Expand Up @@ -89,6 +94,7 @@ export const checkCriteria = async (
{
client: httpClient,
method: 'post',
signal: AbortSignal.timeout(remoteTimeout),
body: JSON.stringify({ entry }),
headers: getHeader(GlobalAuth.token),
},
Expand Down
7 changes: 7 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ export type SwitcherOptions = {
* If not set, it will use the default certificate
*/
certPath?: string;

/**
* The remote timeout in milliseconds for crieteria evaluation API calls
*
* If not set, it will use the default value (2000 ms)
*/
remoteTimeout?: number;
};

export type RetryOptions = {
Expand Down
5 changes: 5 additions & 0 deletions tests/switcher-context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ describe('Switcher Context:', function () {
Error, 'Something went wrong: URL is required');
});

it('should NOT throw when remoteTimeout is set', function() {
Client.buildContext(contextSettings, { remoteTimeout: 5000 });
assertTrue(true);
});

it('should be invalid - Missing API Key field', async function () {
// given
given('POST@/criteria/auth', generateAuth('[auth_token]', 5));
Expand Down
Loading