Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Refactor is-auth-ready tests to use auth-types OAS only
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Oct 3, 2017
1 parent 1ebf0f4 commit f1b20dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"post": {
"security": [
{
"oauth2": ["write:things"]
"oauth": ["write:things"]
}
]
}
Expand Down
28 changes: 13 additions & 15 deletions packages/api-explorer-ui/__tests__/lib/is-auth-ready.test.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
const isAuthReady = require('../../src/lib/is-auth-ready');
const Oas = require('../../src/lib/Oas.js');
const petstore = require('../fixtures/petstore/oas');
const auth = require('../fixtures/auth-types/oas');
const authTypesOas = require('../fixtures/auth-types/oas');

const oas = new Oas(petstore);
const oas2 = new Oas(auth);
const oas = new Oas(authTypesOas);

describe('isAuthReady', () => {
it('should return true if auth data is passed in correctly for api key condition', () => {
const operation = oas.operation('/pet/{petId}', 'get');
const operation = oas.operation('/api-key', 'post');

expect(isAuthReady(operation, { api_key: 'test' })).toBe(true);
expect(isAuthReady(operation, { apiKey: 'test' })).toBe(true);
});

it('should return false if auth data is not passed in for api key condition', () => {
const operation = oas.operation('/pet/{petId}', 'get');
const operation = oas.operation('/api-key', 'post');

expect(isAuthReady(operation, { api_key: '' })).toBe(false);
expect(isAuthReady(operation, { apiKey: '' })).toBe(false);
});

it('should return false if auth data is not passed in correctly for oauth condition', () => {
const operation = oas.operation('/pet/{petId}', 'delete');
const operation = oas.operation('/oauth', 'post');

expect(isAuthReady(operation, { petstore_auth: '' })).toBe(false);
expect(isAuthReady(operation, { oauth: '' })).toBe(false);
});

it('should return true if auth data is passed in correctly for oauth condition', () => {
const operation = oas.operation('/pet/{petId}', 'delete');
const operation = oas.operation('/oauth', 'post');

expect(isAuthReady(operation, { petstore_auth: 'ouath' })).toBe(true);
expect(isAuthReady(operation, { oauth: 'bearer' })).toBe(true);
});

it('should return true if auth data is passed in for basic condition', () => {
const operation = oas2.operation('/basic', 'post');
const operation = oas.operation('/basic', 'post');

expect(isAuthReady(operation, { basic: { username: 'test', password: 'pass' } })).toBe(true);
});

it('should return false if auth data is not passed in for basic condition', () => {
const operation = oas2.operation('/basic', 'post');
const operation = oas.operation('/basic', 'post');

expect(isAuthReady(operation, { basic: { username: '', password: '' } })).toBe(false);
});

it('should return true if endpoint does not need auth or passed in auth is correct', () => {
const operation = oas.operation('/store/order/{orderId}', 'get');
const operation = oas.operation('/no-auth', 'post');

expect(isAuthReady(operation)).toBe(true);
});
Expand Down

0 comments on commit f1b20dc

Please sign in to comment.