Skip to content
Closed
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ The list of props for the AsyncAPI React component includes:

- **schema: string | AsyncAPIDocument | object | FetchingSchemaInterface**

The `schema` property is required and contains AsyncAPI specification. Use the `string` type, the [`AsyncAPIDocument`](https://github.com/asyncapi/parser-js/blob/master/lib/models/asyncapi.js) type, parsed specification as JS object from [AsyncAPI Parser](https://github.com/asyncapi/parser-js) or the [`FetchingSchemaInterface`](./library/src/types.ts#L393) object to fetch the schema from an external resource. For more information on what it contains and what it should look like, read [AsyncAPI Specification](https://github.com/asyncapi/asyncapi#asyncapi-specification).
The `schema` property is required and contains AsyncAPI specification. Use the `string` type, the [`AsyncAPIDocument`](https://github.com/asyncapi/parser-js/blob/master/packages/parser/src/models/asyncapi.ts) type, parsed specification as JS object from [AsyncAPI Parser](https://github.com/asyncapi/parser-js) or the [`FetchingSchemaInterface`](./library/src/types.ts#L393) object to fetch the schema from an external resource. For more information on what it contains and what it should look like, read [AsyncAPI Specification](https://github.com/asyncapi/asyncapi#asyncapi-specification).

- **config?: Partial<ConfigInterface\>**

Expand Down
112 changes: 112 additions & 0 deletions library/src/helpers/__tests__/server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { ServerHelpers } from '../server';

describe('ServerHelpers', () => {
describe('.securityType', () => {
test('should map known security types', () => {
expect(ServerHelpers.securityType('apiKey')).toBe('API key');
expect(ServerHelpers.securityType('oauth2')).toBe('OAuth2');
expect(ServerHelpers.securityType('scramSha256')).toBe('ScramSha256');
});

test('should fallback to default', () => {
expect(ServerHelpers.securityType('unknown')).toBe('API key');
});
});

describe('.flowName', () => {
test('should map known flow names', () => {
expect(ServerHelpers.flowName('implicit')).toBe('Implicit');
expect(ServerHelpers.flowName('password')).toBe('Password');
expect(ServerHelpers.flowName('authorizationCode')).toBe(
'Authorization Code',
);
});

test('should fallback to default', () => {
expect(ServerHelpers.flowName('unknown')).toBe('Implicit');
});
});

describe('.getKafkaSecurity', () => {
const mockSecurity = (type: string) =>
({
type: () => type,
} as any);

test('kafka protocol without security', () => {
const result = ServerHelpers.getKafkaSecurity('kafka', null);
expect(result).toEqual({
securityProtocol: 'PLAINTEXT',
saslMechanism: undefined,
});
});

test('kafka protocol with security', () => {
const result = ServerHelpers.getKafkaSecurity(
'kafka',
mockSecurity('plain'),
);

expect(result).toEqual({
securityProtocol: 'SASL_PLAINTEXT',
saslMechanism: 'PLAIN',
});
});

test('non-kafka protocol without security', () => {
const result = ServerHelpers.getKafkaSecurity('amqp', null);
expect(result).toEqual({
securityProtocol: 'SSL',
saslMechanism: undefined,
});
});

test('non-kafka protocol with security', () => {
const result = ServerHelpers.getKafkaSecurity(
'amqp',
mockSecurity('scramSha256'),
);

expect(result).toEqual({
securityProtocol: 'SASL_SSL',
saslMechanism: 'SCRAM-SHA-256',
});
});

test('scramSha512 mechanism', () => {
const result = ServerHelpers.getKafkaSecurity(
'kafka',
mockSecurity('scramSha512'),
);

expect(result.saslMechanism).toBe('SCRAM-SHA-512');
});

test('oauth2 mechanism', () => {
const result = ServerHelpers.getKafkaSecurity(
'kafka',
mockSecurity('oauth2'),
);

expect(result.saslMechanism).toBe('OAUTHBEARER');
});

test('gssapi mechanism', () => {
const result = ServerHelpers.getKafkaSecurity(
'kafka',
mockSecurity('gssapi'),
);

expect(result.saslMechanism).toBe('GSSAPI');
});

test('X509 forces SSL protocol', () => {
const result = ServerHelpers.getKafkaSecurity(
'kafka',
mockSecurity('X509'),
);

expect(result.securityProtocol).toBe('SSL');
});
});
});