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: Derek Ho <[email protected]>
- Loading branch information
Showing
7 changed files
with
357 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 { SecurityPluginConfigType } from '../../../index'; | ||
import { SecuritySessionCookie } from '../../../session/security_cookie'; | ||
import { | ||
IRouter, | ||
CoreSetup, | ||
ILegacyClusterClient, | ||
Logger, | ||
SessionStorageFactory, | ||
} from '../../../../../../src/core/server'; | ||
import { BasicAuthentication } from './basic_auth'; | ||
|
||
describe('Basic auth tests', () => { | ||
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 = ({ | ||
saml: { | ||
extra_storage: { | ||
cookie_prefix: 'testcookie', | ||
additional_cookies: 5, | ||
}, | ||
}, | ||
session: { | ||
ttl: 1000, | ||
}, | ||
} as unknown) as SecurityPluginConfigType; | ||
|
||
test('getKeepAliveExpiry', () => { | ||
const realDateNow = Date.now.bind(global.Date); | ||
const dateNowStub = jest.fn(() => 0); | ||
global.Date.now = dateNowStub; | ||
const proxyAuthentication = new BasicAuthentication( | ||
config, | ||
sessionStorageFactory, | ||
router, | ||
esClient, | ||
core, | ||
logger | ||
); | ||
|
||
const cookie: SecuritySessionCookie = { | ||
credentials: { | ||
authHeaderValueExtra: true, | ||
}, | ||
expiryTime: 0, | ||
}; | ||
|
||
const request = httpServerMock.createOpenSearchDashboardsRequest({ | ||
path: '/internal/v1', | ||
}); | ||
|
||
expect(proxyAuthentication.getKeepAliveExpiry(cookie, request)).toBe(1000); | ||
global.Date.now = realDateNow; | ||
}); | ||
}); |
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,78 @@ | ||
/* | ||
* 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 { SecurityPluginConfigType } from '../../../index'; | ||
import { SecuritySessionCookie } from '../../../session/security_cookie'; | ||
import { deflateValue } from '../../../utils/compression'; | ||
import { | ||
IRouter, | ||
CoreSetup, | ||
ILegacyClusterClient, | ||
Logger, | ||
SessionStorageFactory, | ||
} from '../../../../../../src/core/server'; | ||
import { MultipleAuthentication } from './multi_auth'; | ||
|
||
describe('Multi auth tests', () => { | ||
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 = ({ | ||
session: { | ||
ttl: 1000, | ||
}, | ||
auth: { | ||
type: 'basic', | ||
}, | ||
} as unknown) as SecurityPluginConfigType; | ||
|
||
test('getKeepAliveExpiry', () => { | ||
const realDateNow = Date.now.bind(global.Date); | ||
const dateNowStub = jest.fn(() => 0); | ||
global.Date.now = dateNowStub; | ||
const proxyAuthentication = new MultipleAuthentication( | ||
config, | ||
sessionStorageFactory, | ||
router, | ||
esClient, | ||
core, | ||
logger | ||
); | ||
|
||
const cookie: SecuritySessionCookie = { | ||
credentials: { | ||
authHeaderValueExtra: true, | ||
}, | ||
expiryTime: 1000, | ||
}; | ||
|
||
const request = httpServerMock.createOpenSearchDashboardsRequest({ | ||
path: '/internal/v1', | ||
}); | ||
|
||
expect(proxyAuthentication.getKeepAliveExpiry(cookie, request)).toBe(1000); // Multi auth using basic auth's implementation | ||
global.Date.now = realDateNow; | ||
}); | ||
}); |
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,78 @@ | ||
/* | ||
* 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 { SecurityPluginConfigType } from '../../../index'; | ||
import { SecuritySessionCookie } from '../../../session/security_cookie'; | ||
import { | ||
IRouter, | ||
CoreSetup, | ||
ILegacyClusterClient, | ||
Logger, | ||
SessionStorageFactory, | ||
} from '../../../../../../src/core/server'; | ||
import { ProxyAuthentication } from './proxy_auth'; | ||
|
||
describe('Proxy auth tests', () => { | ||
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 = ({ | ||
saml: { | ||
extra_storage: { | ||
cookie_prefix: 'testcookie', | ||
additional_cookies: 5, | ||
}, | ||
}, | ||
session: { | ||
ttl: 1000, | ||
}, | ||
} as unknown) as SecurityPluginConfigType; | ||
|
||
test('getKeepAliveExpiry', () => { | ||
const realDateNow = Date.now.bind(global.Date); | ||
const dateNowStub = jest.fn(() => 0); | ||
global.Date.now = dateNowStub; | ||
const proxyAuthentication = new ProxyAuthentication( | ||
config, | ||
sessionStorageFactory, | ||
router, | ||
esClient, | ||
core, | ||
logger | ||
); | ||
|
||
const cookie: SecuritySessionCookie = { | ||
credentials: { | ||
authHeaderValueExtra: true, | ||
}, | ||
expiryTime: 1000, | ||
}; | ||
|
||
const request = httpServerMock.createOpenSearchDashboardsRequest({ | ||
path: '/internal/v1', | ||
}); | ||
|
||
expect(proxyAuthentication.getKeepAliveExpiry(cookie, request)).toBe(1000); | ||
global.Date.now = realDateNow; | ||
}); | ||
}); |
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