forked from opensearch-project/security-dashboards-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jochen Kressin <[email protected]>
- Loading branch information
1 parent
fba07b8
commit 335c1da
Showing
14 changed files
with
919 additions
and
28 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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import { httpServerMock } from '../../../../../../src/core/server/http/http_server.mocks'; | ||
|
||
import { OpenSearchDashboardsRequest } from '../../../../../../src/core/server/http/router'; | ||
|
||
import { OpenIdAuthentication } from './openid_auth'; | ||
import { SecurityPluginConfigType } from '../../../index'; | ||
import { SecuritySessionCookie } from '../../../session/security_cookie'; | ||
import { deflateValue } from '../../../utils/compression'; | ||
import { | ||
IRouter, | ||
CoreSetup, | ||
ILegacyClusterClient, | ||
Logger, | ||
SessionStorageFactory, | ||
} from '../../../../../../src/core/server'; | ||
|
||
describe('test OpenId authHeaderValue', () => { | ||
let router: IRouter; | ||
let core: CoreSetup; | ||
let esClient: ILegacyClusterClient; | ||
let sessionStorageFactory: SessionStorageFactory<SecuritySessionCookie>; | ||
let logger: Logger; | ||
|
||
// Consistent with auth_handler_factory.test.ts | ||
beforeEach(() => {}); | ||
|
||
const config = ({ | ||
openid: { | ||
header: 'authorization', | ||
scope: [], | ||
extra_storage: { | ||
cookie_prefix: 'testcookie', | ||
additional_cookies: 5, | ||
}, | ||
}, | ||
} as unknown) as SecurityPluginConfigType; | ||
|
||
test('make sure that cookies with authHeaderValue are still valid', async () => { | ||
const openIdAuthentication = new OpenIdAuthentication( | ||
config, | ||
sessionStorageFactory, | ||
router, | ||
esClient, | ||
core, | ||
logger | ||
); | ||
|
||
const mockRequest = httpServerMock.createRawRequest(); | ||
const osRequest = OpenSearchDashboardsRequest.from(mockRequest); | ||
|
||
const cookie: SecuritySessionCookie = { | ||
credentials: { | ||
authHeaderValue: 'Bearer eyToken', | ||
}, | ||
}; | ||
|
||
const expectedHeaders = { | ||
authorization: 'Bearer eyToken', | ||
}; | ||
|
||
const headers = openIdAuthentication.buildAuthHeaderFromCookie(cookie, osRequest); | ||
|
||
expect(headers).toEqual(expectedHeaders); | ||
}); | ||
|
||
test('get authHeaderValue from split cookies', async () => { | ||
const openIdAuthentication = new OpenIdAuthentication( | ||
config, | ||
sessionStorageFactory, | ||
router, | ||
esClient, | ||
core, | ||
logger | ||
); | ||
|
||
const testString = 'Bearer eyCombinedToken'; | ||
const testStringBuffer: Buffer = deflateValue(testString); | ||
const cookieValue = testStringBuffer.toString('base64'); | ||
const cookiePrefix = config.openid!.extra_storage.cookie_prefix; | ||
const splitValueAt = Math.ceil( | ||
cookieValue.length / config.openid!.extra_storage.additional_cookies | ||
); | ||
const mockRequest = httpServerMock.createRawRequest({ | ||
state: { | ||
[cookiePrefix + '1']: cookieValue.substring(0, splitValueAt), | ||
[cookiePrefix + '2']: cookieValue.substring(splitValueAt), | ||
}, | ||
}); | ||
const osRequest = OpenSearchDashboardsRequest.from(mockRequest); | ||
|
||
const cookie: SecuritySessionCookie = { | ||
credentials: { | ||
authHeaderValueExtra: true, | ||
}, | ||
}; | ||
|
||
const expectedHeaders = { | ||
authorization: testString, | ||
}; | ||
|
||
const headers = openIdAuthentication.buildAuthHeaderFromCookie(cookie, osRequest); | ||
|
||
expect(headers).toEqual(expectedHeaders); | ||
}); | ||
}); |
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
Oops, something went wrong.