Skip to content

Commit

Permalink
Add tests for AuthType
Browse files Browse the repository at this point in the history
  • Loading branch information
sujithvm committed Feb 12, 2020
1 parent 492f496 commit f41b24c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"env": {
"test": {
"presets": [["@babel/preset-env"]]
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"start": "plugin-helpers start",
"test:server": "plugin-helpers test:server",
"test:browser": "./node_modules/.bin/jest --clearCache && ./node_modules/.bin/jest --config ./tests/jest.config.js",
"test:jest": "../../kibana/node_modules/.bin/jest --config ./test/jest.config.js",
"test:jest": "./node_modules/.bin/jest --config tests/jest.config.js",
"build": "plugin-helpers build"
},
"dependencies": {
Expand Down
35 changes: 35 additions & 0 deletions tests/AuthType.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import AuthType from "../lib/auth/types/AuthType";

const mockServer = {
config: () => {
return {
get: () => {
return null;
}
}
}
}

describe('AuthType tests', () => {
it('should contain only security_impersonate_as when no additional headers are passed', () => {
// act
var authType = new AuthType(null, mockServer, null, null, null, {});
// assert
expect(authType.allowedAdditionalAuthHeaders).toHaveLength(1);
expect(authType.allowedAdditionalAuthHeaders).toContain("security_impersonate_as");
});

it('should add whitelisted headers when present', () => {
// arrange
const mockEsConfig = {
requestHeadersWhitelist: ["test-header-1", "test-header-2"]
}
// act
var authType = new AuthType(null, mockServer, null, null, null, mockEsConfig);
// assert
expect(authType.allowedAdditionalAuthHeaders).toHaveLength(3);
expect(authType.allowedAdditionalAuthHeaders).toContain("security_impersonate_as");
expect(authType.allowedAdditionalAuthHeaders).toContain("test-header-1");
expect(authType.allowedAdditionalAuthHeaders).toContain("test-header-2")
});
});

0 comments on commit f41b24c

Please sign in to comment.