-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport cookie splitter #1662
Closed
adrian-golawski-eliatra
wants to merge
9
commits into
opensearch-project:1.x
from
adrian-golawski-eliatra:backport-cookie-splitter
Closed
Backport cookie splitter #1662
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
01931ad
Backport cookie compression
jochen-kressin 21e7a42
The cookie splitter should be able to use cookie values that have bee…
jochen-kressin f6f7a89
adding config as per 1x branch and craig p instructions
leanneeliatra 9c3a8f6
Merge branch '1.x' into backport-cookie-splitter
DarshitChanpura 85db227
Mocking for the tests
jochen-kressin 9330781
Checkout 1.3.14 tag
cwperks 38bb292
Lint fixes
jochen-kressin a870d54
Stabilize SAML integ test on 1.3
cwperks 2022b66
removing unneeded version from action.yml. Reverting to dynamic versi…
leanneeliatra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,158 @@ | ||
/* | ||
* 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 esClient: ILegacyClusterClient; | ||
let logger: Logger; | ||
|
||
const router: Partial<IRouter> = { | ||
get: jest.fn(), | ||
post: jest.fn(), | ||
}; | ||
const core = ({ | ||
http: { | ||
basePath: { | ||
serverBasePath: '/', | ||
}, | ||
resources: { | ||
register: jest.fn(), | ||
}, | ||
}, | ||
} as unknown) as CoreSetup; | ||
|
||
const sessionStorageFactory: SessionStorageFactory<SecuritySessionCookie> = { | ||
asScoped: jest.fn().mockImplementation(() => { | ||
return { | ||
server: { | ||
states: { | ||
add: jest.fn(), | ||
}, | ||
}, | ||
}; | ||
}), | ||
}; | ||
|
||
// Consistent with auth_handler_factory.test.ts | ||
beforeEach(() => { | ||
// @ts-ignore | ||
jest.spyOn(OpenIdAuthentication.prototype, 'init').mockImplementation(async () => {}); | ||
}); | ||
|
||
const config = ({ | ||
cookie: { | ||
secure: false, | ||
}, | ||
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 as IRouter, | ||
esClient, | ||
core, | ||
logger | ||
); | ||
|
||
// The init method has a spyOn and is not executed, so we call createExtraStorage separately. | ||
// This is not really needed for the test, but may help in spotting errors. | ||
openIdAuthentication.createExtraStorage(); | ||
|
||
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 as IRouter, | ||
esClient, | ||
core, | ||
logger | ||
); | ||
|
||
// The init method has a spyOn and is not executed, so we call createExtraStorage separately. | ||
// This is not really needed for the test, but may help in spotting errors. | ||
openIdAuthentication.createExtraStorage(); | ||
|
||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why hardcode:
git checkout 1.3.14
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, and maybe that one should go. I cherry picked that commit from Craig's PR, but maybe that was more of a PoC? Without it, the tests would not run, although I can't remember what the error was.
@cwperks Do you know if this was a temporary fix, and what the alternative should be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember correctly, this was added temporarily because the 1.x branch was stale and #1688 was not merged yet. Since the branch was stale, it was trying to check out an older patch release of OSD core so I added this line in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @DarshitChanpura is the comment you were awaiting addressed above please, just checking? Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be removed then I think since the branch is not longer stale.