Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0859753
Add support for AuthPlugins
mofojed Mar 21, 2023
a6065ff
Pass the auth config values to the login plugin
mofojed Mar 22, 2023
c128f82
Add core auth plugins to UI
mofojed Mar 28, 2023
0ef2deb
Add some documentation to auth-plugin about usage
mofojed Mar 28, 2023
8269b59
Add tests for auth plugins, examples to docs
mofojed Mar 29, 2023
4f68c04
Only allow AuthPluginParent when authProvider=parent set
mofojed Mar 29, 2023
cffc364
Merge remote-tracking branch 'origin/main' into auth-plugins
mofojed Apr 11, 2023
7cce112
WIP add a TODO to login in the embedded apps
mofojed Apr 11, 2023
3361741
Pull plugins into their own package, plugin-utils
mofojed Apr 17, 2023
231e0ef
Move loading plugins into it's own util function
mofojed Apr 17, 2023
a3750af
Merge remote-tracking branch 'origin/main' into auth-plugins
mofojed Apr 17, 2023
77e6cff
Fix up conflicts after merging latest main
mofojed Apr 17, 2023
716dd7c
Refactor some of the app initialization code
mofojed Apr 17, 2023
54521f5
Move getClientOptions to the app-utils package
mofojed Apr 18, 2023
c1f89f9
Added initialization bootstrap to app-utils
mofojed Apr 19, 2023
0959b1d
Fix up unit tests and style guide
mofojed Apr 19, 2023
fde0dea
Add AppBootstrap to embed-grid application
mofojed Apr 19, 2023
f5a1c92
Update embed-chart to use AppBootstrap
mofojed Apr 19, 2023
9ac1104
Clean up app-utils based on self-review
mofojed Apr 19, 2023
e5a8fea
Fix plugins loading in embed-grid and embed-chart
mofojed Apr 19, 2023
8cb5884
More cleanup on self-review
mofojed Apr 19, 2023
6964acc
Cleanup after review
mofojed Apr 20, 2023
4f7c5c4
Fix failing tests
mofojed Apr 20, 2023
2a689a6
Add authentication keyword
mofojed Apr 20, 2023
671a083
Merge remote-tracking branch 'origin/main' into auth-plugins
mofojed Apr 20, 2023
0eac926
Add some unit tests for AppBootstrap
mofojed Apr 20, 2023
6882a2f
Add a comment explaining why using useContext instead of usePlugins
mofojed Apr 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __mocks__/dh-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@ class CoreClient {
}
}

CoreClient.LOGIN_TYPE_ANONYMOUS = 'MOCK_LOGIN_ANONYNOUS';

class FileContents {
static text(...text) {
return new FileContents(text.join(''));
Expand Down
69 changes: 69 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions packages/auth-core-plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build
/dist

# misc
.vscode
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.project
.settings/
.eslintcache
.stylelintcache

/public/vs

npm-debug.log*
yarn-debug.log*
yarn-error.log*

src/**/*.css
23 changes: 23 additions & 0 deletions packages/auth-core-plugins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# @deephaven/jsapi-utils

A library with some JS utility methods for interacting with the JSAPI.

## Install

```bash
npm install --save @deephaven/jsapi-utils
```

## Usage

```javascript
import { TableUtils } from '@deephaven/jsapi-utils';

if (TableUtils.isDateType(columnType)) {
console.log('Date type', columnType);
} else if (TableUtils.isNumberType(columnType)) {
console.log('Number type', columnType);
} else {
console.log('Unrecognized type', columnType);
}
```
8 changes: 8 additions & 0 deletions packages/auth-core-plugins/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const baseConfig = require('../../jest.config.base.cjs');
const packageJson = require('./package');

module.exports = {
...baseConfig,
displayName: packageJson.name,
resetMocks: false,
};
53 changes: 53 additions & 0 deletions packages/auth-core-plugins/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@deephaven/auth-core-plugins",
"version": "0.32.0",
"description": "Deephaven Auth Core Plugins",
"keywords": [
"Deephaven",
"plugin",
"deephaven-js-plugin",
"auth",
"anonymous",
"parent",
"psk",
"Pre-shared key"
],
"author": "Deephaven Data Labs LLC",
"license": "Apache-2.0",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/deephaven/web-client-ui.git",
"directory": "packages/auth-plugin"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"source": "src/index.ts",
"engines": {
"node": ">=16"
},
"scripts": {
"build": "cross-env NODE_ENV=production run-p build:*",
"build:babel": "babel ./src --out-dir ./dist --extensions \".ts,.tsx,.js,.jsx\" --source-maps --root-mode upward"
},
"dependencies": {
"@deephaven/auth-plugin": "file:../auth-plugin",
"@deephaven/components": "file:../components",
"@deephaven/log": "file:../log",
"@deephaven/jsapi-bootstrap": "file:../jsapi-bootstrap",
"@deephaven/jsapi-types": "file:../jsapi-types"
},
"devDependencies": {
"@deephaven/tsconfig": "file:../tsconfig",
"@types/react": "^17.0.2"
},
"peerDependencies": {
"react": "^17.x"
},
"files": [
"dist"
],
Comment thread
mofojed marked this conversation as resolved.
"publishConfig": {
"access": "public"
}
}
5 changes: 5 additions & 0 deletions packages/auth-core-plugins/src/AuthHandlerTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const AUTH_HANDLER_TYPE_ANONYMOUS =
'io.deephaven.auth.AnonymousAuthenticationHandler';

export const AUTH_HANDLER_TYPE_PSK =
'io.deephaven.authentication.psk.PskAuthenticationHandler';
Comment thread
mofojed marked this conversation as resolved.
109 changes: 109 additions & 0 deletions packages/auth-core-plugins/src/AuthPluginAnonymous.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import React from 'react';
import { act, render, screen } from '@testing-library/react';
import { ApiContext } from '@deephaven/jsapi-bootstrap';
import { dh } from '@deephaven/jsapi-shim';
import AuthPluginAnonymous from './AuthPluginAnonymous';
import { AUTH_HANDLER_TYPE_ANONYMOUS as AUTH_TYPE } from './AuthHandlerTypes';

function makeCoreClient() {
return new dh.CoreClient('wss://test.mockurl.example.com');
}

describe('availability tests', () => {
const client = makeCoreClient();
const authConfigValues = new Map();
it.each([
[[AUTH_TYPE], true],
[['another.type', AUTH_TYPE], true],
[[], false],
[
['not-anonymous', `${AUTH_TYPE}.withsuffix`, `prefix.${AUTH_TYPE}`],
false,
],
])(
'returns availability based on auth handlers: %s',
(authHandlers, result) => {
expect(
AuthPluginAnonymous.isAvailable(client, authHandlers, authConfigValues)
).toBe(result);
}
);
});

function expectLoading() {
expect(screen.queryByTestId('auth-anonymous-loading')).not.toBeNull();
}

describe('component tests', () => {
const authConfigValues = new Map();
it('attempts to login on mount, calls success', async () => {
const loginPromise = Promise.resolve();
const onSuccess = jest.fn();
const onFailure = jest.fn();
const mockLogin = jest.fn(() => loginPromise);
const client = makeCoreClient();
client.login = mockLogin;
render(
<ApiContext.Provider value={dh}>
<AuthPluginAnonymous.Component
authConfigValues={authConfigValues}
client={client}
onFailure={onFailure}
onSuccess={onSuccess}
/>
</ApiContext.Provider>
);
expectLoading();
expect(onSuccess).not.toHaveBeenCalled();
expect(onFailure).not.toHaveBeenCalled();
expect(mockLogin).toHaveBeenCalledWith(
expect.objectContaining({
type: dh.CoreClient.LOGIN_TYPE_ANONYMOUS,
})
);

await loginPromise;

expect(onSuccess).toHaveBeenCalled();
expect(onFailure).not.toHaveBeenCalled();
});

it('attempts to login on mount, calls failure if login fails', async () => {
const error = 'Mock test error';
const loginPromise = Promise.reject(error);
const onSuccess = jest.fn();
const onFailure = jest.fn();
const mockLogin = jest.fn(() => loginPromise);
const client = makeCoreClient();
client.login = mockLogin;
render(
<ApiContext.Provider value={dh}>
<AuthPluginAnonymous.Component
authConfigValues={authConfigValues}
client={client}
onFailure={onFailure}
onSuccess={onSuccess}
/>
</ApiContext.Provider>
);
expectLoading();
expect(onSuccess).not.toHaveBeenCalled();
expect(onFailure).not.toHaveBeenCalled();
expect(mockLogin).toHaveBeenCalledWith(
expect.objectContaining({
type: dh.CoreClient.LOGIN_TYPE_ANONYMOUS,
})
);

await act(async () => {
try {
await loginPromise;
} catch (e) {
// We know it fails
}
});

expect(onSuccess).not.toHaveBeenCalled();
expect(onFailure).toHaveBeenCalledWith(error);
});
});
Loading