Skip to content

Commit

Permalink
Fix typescript errors in bh-shared-ui (#1042)
Browse files Browse the repository at this point in the history
* chore: ensure type check runs before build in `bh-shared-ui` and `js-client-library`

* feat: added new github workflow `build-ui.yml`

* chore: fix typescript errors in `bh-shared-ui`

* chore: add `js-file-download` to list of external dependencies when building `bh-shared-ui`

* chore: rename job, remove "BED-5219" from list of branches that the job runs on when a new commit is pushed
  • Loading branch information
elikmiller authored Dec 30, 2024
1 parent cd4233a commit c704775
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 6 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build-ui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2024 Specter Ops, Inc.
#
# Licensed under the Apache License, Version 2.0
# 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.
#
# SPDX-License-Identifier: Apache-2.0

name: Build UI

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize]

jobs:
build-ui:
runs-on: ubuntu-latest

steps:
- name: Checkout source code for this repository
uses: actions/checkout@v3

- name: Install Node
uses: actions/setup-node@v4
with:
node-version: 22

- name: Install Yarn
run: |
npm install --global yarn
- name: Install Deps
run: |
cd cmd/ui && yarn
- name: Run Build
run: |
cd cmd/ui && yarn build
2 changes: 1 addition & 1 deletion packages/javascript/bh-shared-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"type": "module",
"scripts": {
"build": "rollup -c rollup.config.js",
"build": "yarn check-types && rollup -c rollup.config.js",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"test": "TZ=America/Los_Angeles vitest",
"check-types": "tsc --noEmit --pretty",
Expand Down
1 change: 1 addition & 0 deletions packages/javascript/bh-shared-ui/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default {
'notistack',
'react-query',
'js-client-library',
'js-file-download',
'swagger-ui-react',
'swagger-ui-react/swagger-ui.css',
'prop-types',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const testSSOProviders: SSOProvider[] = [
sp_metadata_uri: '',
sp_acs_uri: '',
} as SAMLProviderInfo,
login_uri: '',
callback_uri: '',
created_at: '',
updated_at: '',
},
Expand All @@ -60,6 +62,8 @@ const testSSOProviders: SSOProvider[] = [
sp_metadata_uri: '',
sp_acs_uri: '',
} as SAMLProviderInfo,
login_uri: '',
callback_uri: '',
created_at: '',
updated_at: '',
},
Expand All @@ -77,6 +81,8 @@ const testSSOProviders: SSOProvider[] = [
sp_metadata_uri: '',
sp_acs_uri: '',
} as SAMLProviderInfo,
login_uri: '',
callback_uri: '',
created_at: '',
updated_at: '',
},
Expand All @@ -94,6 +100,8 @@ const testSSOProviders: SSOProvider[] = [
sp_metadata_uri: '',
sp_acs_uri: '',
} as SAMLProviderInfo,
login_uri: '',
callback_uri: '',
created_at: '',
updated_at: '',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const testSSOProviders: SSOProvider[] = [
created_at: '',
updated_at: '',
},
login_uri: '',
callback_uri: '',
id: 1,
created_at: '',
updated_at: '',
Expand All @@ -55,6 +57,8 @@ const testSSOProviders: SSOProvider[] = [
created_at: '',
updated_at: '',
},
login_uri: '',
callback_uri: '',
id: 2,
created_at: '',
updated_at: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const samlProvider: SSOProvider = {
sp_metadata_uri: 'http://bloodhound.localhost/api/v2/login/saml/test-idp-2/metadata',
sp_acs_uri: 'http://bloodhound.localhost/api/v2/login/saml/test-idp-2/acs',
} as SAMLProviderInfo,
login_uri: '',
callback_uri: '',
created_at: '2022-02-24T23:38:41.420271Z',
updated_at: '2022-02-24T23:38:41.420271Z',
};
Expand All @@ -46,6 +48,8 @@ const oidcProvider: SSOProvider = {
issuer: 'http://bloodhound.localhost/test-idp-2',
client_id: 'gotham-oidc',
} as OIDCProviderInfo,
login_uri: '',
callback_uri: '',
created_at: '2022-02-24T23:38:41.420271Z',
updated_at: '2022-02-24T23:38:41.420271Z',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const samlProvider: SSOProvider = {
slug: 'gotham-saml',
name: 'Gotham SAML',
type: 'SAML',
login_uri: '',
callback_uri: '',
created_at: '2022-02-24T23:38:41.420271Z',
updated_at: '2022-02-24T23:38:41.420271Z',
details: {} as SAMLProviderInfo,
Expand All @@ -35,6 +37,8 @@ const oidcProvider: SSOProvider = {
slug: 'gotham-oidc',
name: 'Gotham OIDC',
type: 'OIDC',
login_uri: '',
callback_uri: '',
created_at: '2022-02-24T23:38:41.420271Z',
updated_at: '2022-02-24T23:38:41.420271Z',
details: {} as OIDCProviderInfo,
Expand All @@ -45,6 +49,7 @@ const ssoProviders = [samlProvider, oidcProvider];
describe('SSOProviderTable', () => {
const onClickSSOProvider = vi.fn();
const onDeleteSSOProvider = vi.fn();
const onUpdateSSOProvider = vi.fn();

it('should render', async () => {
const onToggleTypeSortOrder = vi.fn();
Expand All @@ -55,6 +60,7 @@ describe('SSOProviderTable', () => {
loading={false}
onClickSSOProvider={onClickSSOProvider}
onDeleteSSOProvider={onDeleteSSOProvider}
onUpdateSSOProvider={onUpdateSSOProvider}
onToggleTypeSortOrder={onToggleTypeSortOrder}
/>
);
Expand Down Expand Up @@ -82,6 +88,7 @@ describe('SSOProviderTable', () => {
loading={false}
onClickSSOProvider={onClickSSOProvider}
onDeleteSSOProvider={onDeleteSSOProvider}
onUpdateSSOProvider={onUpdateSSOProvider}
onToggleTypeSortOrder={onToggleTypeSortOrder}
typeSortOrder={typeSortOrder}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const testSSOProviders: SSOProvider[] = [
created_at: '2024-01-01T12:00:00Z',
updated_at: '2024-01-01T12:00:00Z',
},
login_uri: '',
callback_uri: '',
id: 1,
created_at: '2024-01-01T12:00:00Z',
updated_at: '2024-01-01T12:00:00Z',
Expand All @@ -71,6 +73,8 @@ const testSSOProviders: SSOProvider[] = [
created_at: '2024-01-01T12:00:00Z',
updated_at: '2024-01-01T12:00:00Z',
},
login_uri: '',
callback_uri: '',
id: 2,
created_at: '2024-01-01T12:00:00Z',
updated_at: '2024-01-01T12:00:00Z',
Expand All @@ -94,6 +98,8 @@ const testSSOProviders: SSOProvider[] = [
created_at: '2024-01-01T12:00:00Z',
updated_at: '2024-01-01T12:00:00Z',
},
login_uri: '',
callback_uri: '',
id: 3,
created_at: '2024-01-01T12:00:00Z',
updated_at: '2024-01-01T12:00:00Z',
Expand All @@ -117,6 +123,8 @@ const testSSOProviders: SSOProvider[] = [
created_at: '2024-01-01T12:00:00Z',
updated_at: '2024-01-01T12:00:00Z',
},
login_uri: '',
callback_uri: '',
id: 4,
created_at: '2024-01-01T12:00:00Z',
updated_at: '2024-01-01T12:00:00Z',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('UpsertSAMLProviderForm', () => {
it('should render inputs, labels, and action buttons', () => {
const testOnClose = vi.fn();
const testOnSubmit = vi.fn();
render(<UpsertSAMLProviderForm onClose={testOnClose} onSubmit={testOnSubmit} />);
render(<UpsertSAMLProviderForm onClose={testOnClose} onSubmit={testOnSubmit} error={undefined} />);

expect(screen.getByLabelText('SAML Provider Name')).toBeInTheDocument();

Expand All @@ -37,7 +37,7 @@ describe('UpsertSAMLProviderForm', () => {
const user = userEvent.setup();
const testOnClose = vi.fn();
const testOnSubmit = vi.fn();
render(<UpsertSAMLProviderForm onClose={testOnClose} onSubmit={testOnSubmit} />);
render(<UpsertSAMLProviderForm onClose={testOnClose} onSubmit={testOnSubmit} error={undefined} />);

await user.click(screen.getByRole('button', { name: 'Cancel' }));

Expand All @@ -48,7 +48,7 @@ describe('UpsertSAMLProviderForm', () => {
const user = userEvent.setup();
const testOnClose = vi.fn();
const testOnSubmit = vi.fn();
render(<UpsertSAMLProviderForm onClose={testOnClose} onSubmit={testOnSubmit} />);
render(<UpsertSAMLProviderForm onClose={testOnClose} onSubmit={testOnSubmit} error={undefined} />);

await user.click(screen.getByRole('button', { name: 'Submit' }));

Expand All @@ -65,7 +65,7 @@ describe('UpsertSAMLProviderForm', () => {
const testOnSubmit = vi.fn();
const validProviderName = 'test-provider-name';
const validMetadata = new File([], 'test-metadata.xml');
render(<UpsertSAMLProviderForm onClose={testOnClose} onSubmit={testOnSubmit} />);
render(<UpsertSAMLProviderForm onClose={testOnClose} onSubmit={testOnSubmit} error={undefined} />);

await user.type(screen.getByLabelText('SAML Provider Name'), validProviderName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const initialSAMLProvider: SSOProvider = {
sp_metadata_uri: 'http://bloodhound.localhost/api/v2/login/saml/test-idp-1/metadata',
sp_acs_uri: 'http://bloodhound.localhost/api/v2/login/saml/test-idp-1/acs',
} as SAMLProviderInfo,
login_uri: '',
callback_uri: '',
created_at: '2022-02-24T23:38:41.420271Z',
updated_at: '2022-02-24T23:38:41.420271Z',
};
Expand All @@ -55,6 +57,8 @@ const newSAMLProvider: SSOProvider = {
sp_metadata_uri: 'http://bloodhound.localhost/api/v2/login/saml/test-idp-2/metadata',
sp_acs_uri: 'http://bloodhound.localhost/api/v2/login/saml/test-idp-2/acs',
} as SAMLProviderInfo,
login_uri: '',
callback_uri: '',
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ const testSSOProviders: SSOProvider[] = [
created_at: '2024-01-01T12:00:00Z',
updated_at: '2024-01-01T12:00:00Z',
},
login_uri: '',
callback_uri: '',
id: 1,
created_at: '2024-01-01T12:00:00Z',
updated_at: '2024-01-01T12:00:00Z',
Expand Down
2 changes: 1 addition & 1 deletion packages/javascript/js-client-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"README.md"
],
"scripts": {
"build": "rollup --config rollup.config.js",
"build": "yarn check-types && rollup --config rollup.config.js",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"test": "echo \"Warning: no test specified\"",
"check-types": "tsc --noEmit --pretty",
Expand Down

0 comments on commit c704775

Please sign in to comment.