diff --git a/src/interfaces/providerjson/providerjson.schema.json b/src/interfaces/providerjson/providerjson.schema.json index 50fd84c..7b379cf 100644 --- a/src/interfaces/providerjson/providerjson.schema.json +++ b/src/interfaces/providerjson/providerjson.schema.json @@ -13,6 +13,14 @@ "query" ], "type": "string" + }, + "ApiKeyBodyType": { + "$id": "ApiKeyBodyType", + "description": "Body type to inject security value to.", + "enum": [ + "json" + ], + "type": "string" } }, "description": "Type decribing provider.json document.", diff --git a/src/interfaces/providerjson/providerjson.ts b/src/interfaces/providerjson/providerjson.ts index 854a8a3..5275814 100644 --- a/src/interfaces/providerjson/providerjson.ts +++ b/src/interfaces/providerjson/providerjson.ts @@ -26,7 +26,6 @@ export enum ApiKeyPlacement { export enum HttpScheme { BASIC = 'basic', BEARER = 'bearer', - DIGEST = 'digest', } /** diff --git a/src/interfaces/providerjson/providerjson.utils.test.ts b/src/interfaces/providerjson/providerjson.utils.test.ts index 8c8b373..c17ca72 100644 --- a/src/interfaces/providerjson/providerjson.utils.test.ts +++ b/src/interfaces/providerjson/providerjson.utils.test.ts @@ -1,5 +1,6 @@ import { IntegrationParameter, prepareProviderParameters } from '.'; import { + ApiKeyBodyType, ApiKeyPlacement, HttpScheme, SecurityScheme, @@ -10,7 +11,6 @@ import { isApiKeySecurityScheme, isBasicAuthSecurityScheme, isBearerTokenSecurityScheme, - isDigestSecurityScheme, isValidProviderName, prepareSecurityValues, } from './providerjson.utils'; @@ -42,14 +42,6 @@ describe('ProviderJsonDocument', () => { "id": "swapidev", "type": "http", "scheme": "basic" - }, - { - "id": "swapidev", - "type": "http", - "scheme": "digest", - "statusCode": 401, - "challengeHeader": "www-authenticate", - "authorizationHeader": "authorizaation" } ], "defaultService": "swapidev", @@ -81,15 +73,7 @@ describe('ProviderJsonDocument', () => { id: 'swapidev', type: 'http', scheme: 'basic', - }, - { - id: 'swapidev', - type: 'http', - scheme: 'digest', - statusCode: 401, - challengeHeader: 'www-authenticate', - authorizationHeader: 'authorizaation', - }, + } ], defaultService: 'swapidev', parameters: [{ name: 'userId', description: "some user's id" }], @@ -382,7 +366,8 @@ describe('ProviderJsonDocument', () => { isApiKeySecurityScheme({ id: 'swapidev', type: SecurityType.APIKEY, - in: ApiKeyPlacement.PATH, + in: ApiKeyPlacement.BODY, + bodyType: ApiKeyBodyType.JSON, name: 'X-API-Key', }) ).toEqual(true); @@ -392,7 +377,7 @@ describe('ProviderJsonDocument', () => { isApiKeySecurityScheme({ id: 'swapidev', type: SecurityType.APIKEY, - in: ApiKeyPlacement.QUERY, + in: ApiKeyPlacement.PATH, name: 'X-API-Key', }) ).toEqual(true); @@ -401,17 +386,18 @@ describe('ProviderJsonDocument', () => { expect( isApiKeySecurityScheme({ id: 'swapidev', - type: SecurityType.HTTP, - scheme: HttpScheme.BEARER, + type: SecurityType.APIKEY, + in: ApiKeyPlacement.QUERY, + name: 'X-API-Key', }) - ).toEqual(false); + ).toEqual(true); } { expect( isApiKeySecurityScheme({ id: 'swapidev', type: SecurityType.HTTP, - scheme: HttpScheme.BASIC, + scheme: HttpScheme.BEARER, }) ).toEqual(false); } @@ -420,7 +406,7 @@ describe('ProviderJsonDocument', () => { isApiKeySecurityScheme({ id: 'swapidev', type: SecurityType.HTTP, - scheme: HttpScheme.DIGEST, + scheme: HttpScheme.BASIC, }) ).toEqual(false); } @@ -455,15 +441,6 @@ describe('ProviderJsonDocument', () => { }) ).toEqual(true); } - { - expect( - isBasicAuthSecurityScheme({ - id: 'swapidev', - type: SecurityType.HTTP, - scheme: HttpScheme.DIGEST, - }) - ).toEqual(false); - } }); it('checks BearerTokenSecurity type correctly', () => { @@ -495,101 +472,8 @@ describe('ProviderJsonDocument', () => { }) ).toEqual(false); } - { - expect( - isBearerTokenSecurityScheme({ - id: 'swapidev', - type: SecurityType.HTTP, - scheme: HttpScheme.DIGEST, - }) - ).toEqual(false); - } }); - it('checks DigestAuthSecurity type correctly', () => { - { - expect( - isDigestSecurityScheme({ - id: 'swapidev', - type: SecurityType.APIKEY, - in: ApiKeyPlacement.HEADER, - name: 'X-API-Key', - }) - ).toEqual(false); - } - { - expect( - isDigestSecurityScheme({ - id: 'swapidev', - type: SecurityType.HTTP, - scheme: HttpScheme.BEARER, - }) - ).toEqual(false); - } - { - expect( - isDigestSecurityScheme({ - id: 'swapidev', - type: SecurityType.HTTP, - scheme: HttpScheme.BASIC, - }) - ).toEqual(false); - } - { - expect( - isDigestSecurityScheme({ - id: 'swapidev', - type: SecurityType.HTTP, - scheme: HttpScheme.DIGEST, - }) - ).toEqual(true); - } - { - expect( - isDigestSecurityScheme({ - id: 'swapidev', - type: SecurityType.HTTP, - scheme: HttpScheme.DIGEST, - statusCode: 401, - }) - ).toEqual(true); - } - { - expect( - isDigestSecurityScheme({ - id: 'swapidev', - type: SecurityType.HTTP, - scheme: HttpScheme.DIGEST, - statusCode: 401, - challengeHeader: 'test', - }) - ).toEqual(true); - } - { - expect( - isDigestSecurityScheme({ - id: 'swapidev', - type: SecurityType.HTTP, - scheme: HttpScheme.DIGEST, - statusCode: 401, - challengeHeader: 'test', - authorizationHeader: 'auth', - }) - ).toEqual(true); - } - { - expect( - isDigestSecurityScheme({ - id: 'swapidev', - type: SecurityType.HTTP, - scheme: HttpScheme.DIGEST, - statusCode: undefined, - challengeHeader: undefined, - authorizationHeader: undefined, - }) - ).toEqual(true); - } - }); }); describe('ProviderJson name check', () => { it('checks Provider name correctly', () => { @@ -622,11 +506,6 @@ describe('prepareSecurityValues', () => { type: SecurityType.HTTP, scheme: HttpScheme.BASIC, }, - { - id: 'digest', - type: SecurityType.HTTP, - scheme: HttpScheme.DIGEST, - }, ]; it('prepares security values', () => { @@ -644,11 +523,6 @@ describe('prepareSecurityValues', () => { username: `$TEST_PROVIDER_USERNAME`, password: `$TEST_PROVIDER_PASSWORD`, }, - { - id: 'digest', - username: `$TEST_PROVIDER_USERNAME`, - password: `$TEST_PROVIDER_PASSWORD`, - }, ]); }); diff --git a/src/interfaces/superjson/superjson.schema.json b/src/interfaces/superjson/superjson.schema.json index 0c98f52..2e4f57a 100644 --- a/src/interfaces/superjson/superjson.schema.json +++ b/src/interfaces/superjson/superjson.schema.json @@ -733,28 +733,6 @@ "token" ], "type": "object" - }, - { - "$id": "DigestSecurityValues", - "additionalProperties": false, - "description": "Security values for digest security scheme", - "properties": { - "id": { - "type": "string" - }, - "password": { - "type": "string" - }, - "username": { - "type": "string" - } - }, - "required": [ - "id", - "password", - "username" - ], - "type": "object" } ], "description": "Authorization variables." diff --git a/src/interfaces/superjson/superjson.ts b/src/interfaces/superjson/superjson.ts index 4273fa5..a669050 100644 --- a/src/interfaces/superjson/superjson.ts +++ b/src/interfaces/superjson/superjson.ts @@ -32,18 +32,18 @@ export enum BackoffKind { export type BackoffPolicy = | BackoffKind.EXPONENTIAL | { - kind: BackoffKind.EXPONENTIAL; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - start?: number; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - factor?: number; - }; + kind: BackoffKind.EXPONENTIAL; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + start?: number; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + factor?: number; + }; /** * Retry policy configuration. @@ -51,42 +51,42 @@ export type BackoffPolicy = export type RetryPolicy = | OnFail.NONE | { - kind: OnFail.NONE; - } + kind: OnFail.NONE; + } | OnFail.SIMPLE | { - kind: OnFail.SIMPLE; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - maxContiguousRetries?: number; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - requestTimeout?: number; - } + kind: OnFail.SIMPLE; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + maxContiguousRetries?: number; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + requestTimeout?: number; + } | OnFail.CIRCUIT_BREAKER | { - kind: OnFail.CIRCUIT_BREAKER; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - maxContiguousRetries?: number; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - openTime?: number; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - requestTimeout?: number; - backoff?: BackoffPolicy; - }; + kind: OnFail.CIRCUIT_BREAKER; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + maxContiguousRetries?: number; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + openTime?: number; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + requestTimeout?: number; + backoff?: BackoffPolicy; + }; export type NormalizedBackoffPolicy = { kind: BackoffKind.EXPONENTIAL; @@ -104,40 +104,40 @@ export type NormalizedBackoffPolicy = { export type NormalizedRetryPolicy = | { - kind: OnFail.NONE; - } + kind: OnFail.NONE; + } | { - kind: OnFail.SIMPLE; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - maxContiguousRetries?: number; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - requestTimeout?: number; - } + kind: OnFail.SIMPLE; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + maxContiguousRetries?: number; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + requestTimeout?: number; + } | { - kind: OnFail.CIRCUIT_BREAKER; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - maxContiguousRetries?: number; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - openTime?: number; - /** - * @TJS-minimum 0 - * @TJS-type integer - **/ - requestTimeout?: number; - backoff: NormalizedBackoffPolicy; - }; + kind: OnFail.CIRCUIT_BREAKER; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + maxContiguousRetries?: number; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + openTime?: number; + /** + * @TJS-minimum 0 + * @TJS-type integer + **/ + requestTimeout?: number; + backoff: NormalizedBackoffPolicy; + }; /** * Default per usecase values. @@ -179,25 +179,25 @@ export type NormalizedProfileProviderDefaults = { export type ProfileProviderSettings = { defaults?: ProfileProviderDefaults; } & ( - | { + | { file: string; } - | { + | { mapVariant?: string; mapRevision?: string; } -); + ); export type NormalizedProfileProviderSettings = | { - file: string; - defaults: NormalizedProfileProviderDefaults; - } + file: string; + defaults: NormalizedProfileProviderDefaults; + } | { - mapVariant?: string; - mapRevision?: string; - defaults: NormalizedProfileProviderDefaults; - }; + mapVariant?: string; + mapRevision?: string; + defaults: NormalizedProfileProviderDefaults; + }; /** * Profile provider entry containing either `profileProviderSettings` or shorthands. @@ -212,29 +212,29 @@ export type ProfileSettings = { defaults?: UsecaseDefaults; providers?: { [provider: string]: UriPath | ProfileProviderEntry }; } & ( - | { + | { version: SemanticVersion; } - | { + | { file: string; } -); + ); export type NormalizedProfileSettings = { priority: string[]; defaults: NormalizedUsecaseDefaults; providers: { [provider: string]: NormalizedProfileProviderSettings }; } & ( - | { + | { version: SemanticVersion; } - | { + | { file: string; priority: string[]; defaults: NormalizedUsecaseDefaults; providers: { [provider: string]: NormalizedProfileProviderSettings }; } -); + ); /** * Profile entry containing either `profileSettings` or shorthands. @@ -267,23 +267,13 @@ export type BearerTokenSecurityValues = IdBase & { token: string; }; -/** - * Security values for digest security scheme - * @$id DigestSecurityValues - **/ -export type DigestSecurityValues = IdBase & { - username: string; - password: string; -}; - /** * Authorization variables. */ export type SecurityValues = | ApiKeySecurityValues | BasicAuthSecurityValues - | BearerTokenSecurityValues - | DigestSecurityValues; + | BearerTokenSecurityValues; /** * Expanded provider settings for one provider name. diff --git a/src/interfaces/superjson/superjson.utils.test.ts b/src/interfaces/superjson/superjson.utils.test.ts index 9c840b3..f28aae6 100644 --- a/src/interfaces/superjson/superjson.utils.test.ts +++ b/src/interfaces/superjson/superjson.utils.test.ts @@ -3,7 +3,6 @@ import { isApiKeySecurityValues, isBasicAuthSecurityValues, isBearerTokenSecurityValues, - isDigestSecurityValues, isFileURIString, isVersionString, } from './superjson.utils'; @@ -153,20 +152,4 @@ describe('super.json utils', () => { expect(isBearerTokenSecurityValues({ id: 7 })).toBe(false); }); }); - - describe('isDigestSecurityValues', () => { - it('should return true on valid values', () => { - expect( - isDigestSecurityValues({ - id: 'some-id', - username: 'some-user-name', - password: 'some-password', - }) - ).toBe(true); - }); - - it('should return false on invalid values', () => { - expect(isDigestSecurityValues({ id: 7 })).toBe(false); - }); - }); }); diff --git a/src/interfaces/superjson/superjson.utils.ts b/src/interfaces/superjson/superjson.utils.ts index 6d9630b..99e71b7 100644 --- a/src/interfaces/superjson/superjson.utils.ts +++ b/src/interfaces/superjson/superjson.utils.ts @@ -5,7 +5,6 @@ import { ApiKeySecurityValues, BasicAuthSecurityValues, BearerTokenSecurityValues, - DigestSecurityValues, FILE_URI_REGEX, SEMVER_REGEX, SuperJsonDocument, @@ -40,5 +39,3 @@ export const isBasicAuthSecurityValues: Guard = prepareIs('BasicAuthSecurityValues'); export const isBearerTokenSecurityValues: Guard = prepareIs('BearerTokenSecurityValues'); -export const isDigestSecurityValues: Guard = - prepareIs('DigestSecurityValues');