Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align with OneSDK@3 #107

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## Added
- **BREAKING CHANGE**: Added `bodyType` to `ApiKeySecurityScheme`

## Removed
- **BREAKING CHANGE**: Removed `DigestSecurityScheme`

### Fixed
- Profile AST JSON Schema regenerated

Expand Down
48 changes: 8 additions & 40 deletions src/interfaces/providerjson/providerjson.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
"additionalProperties": false,
"description": "Security scheme for api key authorization.",
"properties": {
"bodyType": {
"$id": "ApiKeyBodyType",
"description": "Body type to inject security value to.",
"enum": [
"json"
],
"type": "string"
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some dark magic happening here. Compared to ApiKeyPlacement if I use $ref on the field, it will be still created in place but with id and ref, so there is circular reference. And I am unable to convince typescript-json-schema library to generate ApiKeyBodyType in definitions. 🤷

"id": {
"type": "string"
},
Expand Down Expand Up @@ -136,46 +144,6 @@
"type"
],
"type": "object"
},
{
"$id": "DigestSecurityScheme",
"additionalProperties": false,
"description": "Security scheme for digest authorization.",
"properties": {
"authorizationHeader": {
"description": "Name of header containing authorization eg. Authorization",
"type": "string"
},
"challengeHeader": {
"description": "Name of header containing challenge from the server eg. www-authenticate",
"type": "string"
},
"id": {
"type": "string"
},
"scheme": {
"enum": [
"digest"
],
"type": "string"
},
"statusCode": {
"description": "Code that should be returned from initial call for challenge eg. 401",
"type": "number"
},
"type": {
"enum": [
"http"
],
"type": "string"
}
},
"required": [
"id",
"scheme",
"type"
],
"type": "object"
}
],
"description": "Type describing general security scheme."
Expand Down
44 changes: 15 additions & 29 deletions src/interfaces/providerjson/providerjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@ export enum SecurityType {
/**
* The placement of the API key.
* @$id ApiKeyPlacement
**/
*/
export enum ApiKeyPlacement {
HEADER = 'header',
BODY = 'body',
PATH = 'path',
QUERY = 'query',
}

/**
* Type of HTTP Authentication Scheme.
*/
export enum HttpScheme {
BASIC = 'basic',
BEARER = 'bearer',
DIGEST = 'digest',
}

/**
* Body type to inject security value to.
* @$id ApiKeyBodyType
*/
export enum ApiKeyBodyType {
JSON = 'json',
}

/**
Expand All @@ -33,10 +43,9 @@ export enum HttpScheme {
export type ApiKeySecurityScheme = {
id: string;
type: SecurityType.APIKEY;
/**
* @$ref ApiKeyPlacement
*/
/** @$ref ApiKeyPlacement */
in: ApiKeyPlacement;
bodyType?: ApiKeyBodyType;
name?: string;
};

Expand All @@ -61,36 +70,13 @@ export type BearerTokenSecurityScheme = {
bearerFormat?: string;
};

/**
* Security scheme for digest authorization.
* @$id DigestSecurityScheme
*/
export type DigestSecurityScheme = {
id: string;
type: SecurityType.HTTP;
scheme: HttpScheme.DIGEST;
/**
* Code that should be returned from initial call for challenge eg. 401
*/
statusCode?: number;
/**
* Name of header containing challenge from the server eg. www-authenticate
*/
challengeHeader?: string;
/**
* Name of header containing authorization eg. Authorization
*/
authorizationHeader?: string;
};

/**
* Type describing general security scheme.
*/
export type SecurityScheme =
| ApiKeySecurityScheme
| BasicAuthSecurityScheme
| BearerTokenSecurityScheme
| DigestSecurityScheme;
| BearerTokenSecurityScheme;

export type ProviderService = {
id: string;
Expand Down
148 changes: 11 additions & 137 deletions src/interfaces/providerjson/providerjson.utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IntegrationParameter, prepareProviderParameters } from '.';
import {
ApiKeyBodyType,
ApiKeyPlacement,
HttpScheme,
SecurityScheme,
Expand All @@ -10,7 +11,6 @@ import {
isApiKeySecurityScheme,
isBasicAuthSecurityScheme,
isBearerTokenSecurityScheme,
isDigestSecurityScheme,
isValidProviderName,
prepareSecurityValues,
} from './providerjson.utils';
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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" }],
Expand Down Expand Up @@ -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);
Expand All @@ -392,7 +377,7 @@ describe('ProviderJsonDocument', () => {
isApiKeySecurityScheme({
id: 'swapidev',
type: SecurityType.APIKEY,
in: ApiKeyPlacement.QUERY,
in: ApiKeyPlacement.PATH,
name: 'X-API-Key',
})
).toEqual(true);
Expand All @@ -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);
}
Expand All @@ -420,7 +406,7 @@ describe('ProviderJsonDocument', () => {
isApiKeySecurityScheme({
id: 'swapidev',
type: SecurityType.HTTP,
scheme: HttpScheme.DIGEST,
scheme: HttpScheme.BASIC,
})
).toEqual(false);
}
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -622,11 +506,6 @@ describe('prepareSecurityValues', () => {
type: SecurityType.HTTP,
scheme: HttpScheme.BASIC,
},
{
id: 'digest',
type: SecurityType.HTTP,
scheme: HttpScheme.DIGEST,
},
];

it('prepares security values', () => {
Expand All @@ -644,11 +523,6 @@ describe('prepareSecurityValues', () => {
username: `$TEST_PROVIDER_USERNAME`,
password: `$TEST_PROVIDER_PASSWORD`,
},
{
id: 'digest',
username: `$TEST_PROVIDER_USERNAME`,
password: `$TEST_PROVIDER_PASSWORD`,
},
]);
});

Expand Down
Loading