-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose AnonymousAccess service through Security OSS plugin. (#87091)
- Loading branch information
Showing
39 changed files
with
1,862 additions
and
240 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
20 changes: 20 additions & 0 deletions
20
...development/core/server/kibana-plugin-core-server.resolvecapabilitiesoptions.md
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,20 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [ResolveCapabilitiesOptions](./kibana-plugin-core-server.resolvecapabilitiesoptions.md) | ||
|
||
## ResolveCapabilitiesOptions interface | ||
|
||
Defines a set of additional options for the `resolveCapabilities` method of [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md)<!-- -->. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface ResolveCapabilitiesOptions | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| [useDefaultCapabilities](./kibana-plugin-core-server.resolvecapabilitiesoptions.usedefaultcapabilities.md) | <code>boolean</code> | Indicates if capability switchers are supposed to return a default set of capabilities. | | ||
|
13 changes: 13 additions & 0 deletions
13
.../kibana-plugin-core-server.resolvecapabilitiesoptions.usedefaultcapabilities.md
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,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [ResolveCapabilitiesOptions](./kibana-plugin-core-server.resolvecapabilitiesoptions.md) > [useDefaultCapabilities](./kibana-plugin-core-server.resolvecapabilitiesoptions.usedefaultcapabilities.md) | ||
|
||
## ResolveCapabilitiesOptions.useDefaultCapabilities property | ||
|
||
Indicates if capability switchers are supposed to return a default set of capabilities. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
useDefaultCapabilities: boolean; | ||
``` |
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
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,29 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
|
||
/** | ||
* Defines Security OSS application state. | ||
*/ | ||
export interface AppState { | ||
insecureClusterAlert: { displayAlert: boolean }; | ||
anonymousAccess: { | ||
isEnabled: boolean; | ||
accessURLParameters: Record<string, string> | null; | ||
}; | ||
} |
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,20 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
|
||
export type { AppState } from './app_state'; |
32 changes: 32 additions & 0 deletions
32
src/plugins/security_oss/public/app_state/app_state_service.mock.ts
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,32 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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 type { AppState } from '../../common'; | ||
import type { AppStateServiceStart } from './app_state_service'; | ||
|
||
export const mockAppStateService = { | ||
createStart: (): jest.Mocked<AppStateServiceStart> => { | ||
return { getState: jest.fn() }; | ||
}, | ||
createAppState: (appState: Partial<AppState> = {}) => ({ | ||
insecureClusterAlert: { displayAlert: false }, | ||
anonymousAccess: { isEnabled: false, accessURLParameters: null }, | ||
...appState, | ||
}), | ||
}; |
72 changes: 72 additions & 0 deletions
72
src/plugins/security_oss/public/app_state/app_state_service.test.ts
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,72 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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 { coreMock } from '../../../../core/public/mocks'; | ||
import { AppStateService } from './app_state_service'; | ||
|
||
describe('AppStateService', () => { | ||
describe('#start', () => { | ||
it('returns default state for the anonymous routes', async () => { | ||
const coreStart = coreMock.createStart(); | ||
coreStart.http.anonymousPaths.isAnonymous.mockReturnValue(true); | ||
|
||
const appStateService = new AppStateService(); | ||
await expect(appStateService.start({ core: coreStart }).getState()).resolves.toEqual({ | ||
insecureClusterAlert: { displayAlert: false }, | ||
anonymousAccess: { isEnabled: false, accessURLParameters: null }, | ||
}); | ||
|
||
expect(coreStart.http.get).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('returns default state if current state cannot be retrieved', async () => { | ||
const coreStart = coreMock.createStart(); | ||
coreStart.http.anonymousPaths.isAnonymous.mockReturnValue(false); | ||
|
||
const failureReason = new Error('Uh oh.'); | ||
coreStart.http.get.mockRejectedValue(failureReason); | ||
|
||
const appStateService = new AppStateService(); | ||
await expect(appStateService.start({ core: coreStart }).getState()).resolves.toEqual({ | ||
insecureClusterAlert: { displayAlert: false }, | ||
anonymousAccess: { isEnabled: false, accessURLParameters: null }, | ||
}); | ||
|
||
expect(coreStart.http.get).toHaveBeenCalledTimes(1); | ||
expect(coreStart.http.get).toHaveBeenCalledWith('/internal/security_oss/app_state'); | ||
}); | ||
|
||
it('returns retrieved state', async () => { | ||
const coreStart = coreMock.createStart(); | ||
coreStart.http.anonymousPaths.isAnonymous.mockReturnValue(false); | ||
|
||
const state = { | ||
insecureClusterAlert: { displayAlert: true }, | ||
anonymousAccess: { isEnabled: true, accessURLParameters: { hint: 'some-hint' } }, | ||
}; | ||
coreStart.http.get.mockResolvedValue(state); | ||
|
||
const appStateService = new AppStateService(); | ||
await expect(appStateService.start({ core: coreStart }).getState()).resolves.toEqual(state); | ||
|
||
expect(coreStart.http.get).toHaveBeenCalledTimes(1); | ||
expect(coreStart.http.get).toHaveBeenCalledWith('/internal/security_oss/app_state'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.