-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* PoC for splitting up a value into multiple cookie payloads Signed-off-by: Jochen Kressin <[email protected]> * Cookie splitting for OpenId and SAML Signed-off-by: Jochen Kressin <[email protected]> * Changes after review comments Signed-off-by: Jochen Kressin <[email protected]> * WIP: First unit tests Signed-off-by: Jochen Kressin <[email protected]> * More unit tests Signed-off-by: Jochen Kressin <[email protected]> * Fix for multi auth, request argument was missing Signed-off-by: Jochen Kressin <[email protected]> * Fixed linting errors Signed-off-by: Jochen Kressin <[email protected]> * Added one additional cookie for the SAML integration tests Signed-off-by: Jochen Kressin <[email protected]> --------- Signed-off-by: Jochen Kressin <[email protected]> Co-authored-by: Stephen Crawford <[email protected]> (cherry picked from commit c5cdbbb) Co-authored-by: Jochen Kressin <[email protected]>
- Loading branch information
1 parent
11be9b0
commit b1fc467
Showing
15 changed files
with
927 additions
and
30 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
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.