-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from sujithvm/opendistro-1.4
Remove session and request header validation check
- Loading branch information
Showing
3 changed files
with
30 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,43 @@ | ||
import AuthType from "../lib/auth/types/AuthType"; | ||
|
||
const mockServer = { | ||
config: () => { | ||
class MockServer { | ||
config() { | ||
return { | ||
get: () => { | ||
return null; | ||
} | ||
} | ||
} | ||
} | ||
register(args) { | ||
this.registerArgs = args; | ||
} | ||
} | ||
|
||
describe('AuthType tests', () => { | ||
it('should contain only security_impersonate_as when no additional headers are passed', () => { | ||
// arrange | ||
var mockServer = new MockServer(); | ||
var authType = new AuthType(() => {}, mockServer, null, null, null, {}); | ||
// act | ||
var authType = new AuthType(null, mockServer, null, null, null, {}); | ||
authType.setupStorage(); | ||
// assert | ||
expect(authType.allowedAdditionalAuthHeaders).toHaveLength(1); | ||
expect(authType.allowedAdditionalAuthHeaders).toContain("security_impersonate_as"); | ||
expect(mockServer.registerArgs.options.allowedHeaders).toHaveLength(1); | ||
expect(mockServer.registerArgs.options.allowedHeaders).toContain("security_impersonate_as"); | ||
}); | ||
|
||
it('should add whitelisted headers when present', () => { | ||
// arrange | ||
var mockServer = new MockServer(); | ||
const mockEsConfig = { | ||
requestHeadersWhitelist: ["test-header-1", "test-header-2"] | ||
} | ||
var authType = new AuthType(() => {}, mockServer, null, null, null, mockEsConfig); | ||
// act | ||
var authType = new AuthType(null, mockServer, null, null, null, mockEsConfig); | ||
authType.setupStorage(); | ||
// 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") | ||
expect(mockServer.registerArgs.options.allowedHeaders).toHaveLength(3); | ||
expect(mockServer.registerArgs.options.allowedHeaders).toContain("security_impersonate_as"); | ||
expect(mockServer.registerArgs.options.allowedHeaders).toContain("test-header-1"); | ||
expect(mockServer.registerArgs.options.allowedHeaders).toContain("test-header-2"); | ||
}); | ||
}); |