Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

App selections should update current auth states #220

Merged
merged 20 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
deeb4de
Wired up `getAuth()` to pass in selected app
domharrington May 31, 2019
cb7d484
Merge branch 'master' into feature/wire-up-selected-app-to-auth
erunion Nov 20, 2019
2699bc2
feat: changing the logs dropdown now updates the authbox and code sample
erunion Nov 21, 2019
b51453c
feat: adding an app dropdown into the authbox
erunion Nov 21, 2019
82f8ffd
Merge branch 'master' into feature/wire-up-selected-app-to-auth
erunion Nov 22, 2019
2bb3ebe
fix: Update packages/api-explorer/src/AuthBox.jsx
erunion Nov 25, 2019
6a4b887
Merge branch 'master' into feature/wire-up-selected-app-to-auth
erunion Nov 25, 2019
92fa995
fix: fixing some typod object usage
erunion Nov 25, 2019
88da9c6
fix: moving the group dropdown up to the header and showing it once
erunion Nov 25, 2019
cab3b2a
fix: reverting changes to the api-logs module since its not needed
erunion Nov 25, 2019
c1622f2
fix: simplifying group changes
erunion Nov 25, 2019
b145f3e
fix: reverting jest to run in band
erunion Nov 25, 2019
4f584d2
fix: excluding dotfiles from the swagger-files directory
erunion Nov 27, 2019
eb6e3a9
feat: basic http auth password inputs are now masked
erunion Nov 27, 2019
9bf52ff
style(AuthBox)
rafegoldberg Dec 6, 2019
1bb2390
refactor(AuthBox): fix prop ordering per eslint
rafegoldberg Dec 6, 2019
e2b5db3
style(AuthBox): remove scroll bar + max-height
rafegoldberg Dec 6, 2019
082b583
fix(AuthBox): conditionally display GroupList select
rafegoldberg Dec 6, 2019
d3a6cb7
style(AuthBox): lighten background color
rafegoldberg Dec 6, 2019
c55f4e8
test(AuthBox): make sure `groups` exists
rafegoldberg Dec 6, 2019
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
28 changes: 28 additions & 0 deletions packages/api-explorer/__tests__/AuthBox.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const props = {
open: false,
operation: oas.operation('/or-security', 'post'),
onChange: () => {},
onGroupChange: () => {},
onSubmit: () => {},
toggle: () => {},
};
Expand Down Expand Up @@ -68,3 +69,30 @@ test('should display multiple securities', () => {

expect(authBox.find('SecurityInput')).toHaveLength(2);
});

describe('group selection', () => {
const groupProps = {
group: 'someid',
groups: [
{ id: '1230', name: 'someid' },
{ id: '7000', name: 'anotherId' },
],
};

it('should only display a single dropdown regardless of the number of securities', () => {
const comp = mount(<AuthBox {...props} {...groupProps} />);

expect(comp.find('select')).toHaveLength(1);
});

it('should update auth on changes', () => {
const onGroupChangeSpy = jest.fn();
const comp = mount(<AuthBox {...props} {...groupProps} onGroupChange={onGroupChangeSpy} />);

const select = comp.find('select');
select.instance().value = '7000';
select.simulate('change');

expect(onGroupChangeSpy).toHaveBeenCalledWith('7000', 'anotherId');
});
});
11 changes: 11 additions & 0 deletions packages/api-explorer/__tests__/lib/get-auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ test('should fetch all auths from the OAS files', () => {
});
});

test('should fetch auths from selected app', () => {
const user = {
keys: [
{ oauthScheme: '111', name: 'app-1' },
{ oauthScheme: '222', name: 'app-2' },
],
};

expect(getAuth(user, { 'api-setting': oas }, 'app-2').oauthScheme).toBe('222');
});

test('should not error if oas.components is not set', () => {
expect(() => {
getAuth({ oauthScheme: 'oauth', apiKeyScheme: 'apikey' }, { 'api-setting': {} });
Expand Down
194 changes: 194 additions & 0 deletions packages/api-explorer/package-lock.json

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

72 changes: 64 additions & 8 deletions packages/api-explorer/src/AuthBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,47 @@ const { Operation } = require('oas');

const SecurityInput = require('./SecurityInput');

function Securities({ authInputRef, operation, onChange, oauth, auth, onSubmit }) {
function GroupsList({ group, groups, onGroupChange }) {
function onSelect({ target }) {
onGroupChange(target.value, target.options[target.selectedIndex].text);
}

if (!groups || (groups && groups.length <= 1)) {
return false;
}

return (
<select onChange={onSelect} style={{ float: 'right' }} value={group}>
{groups.map(item => (
<option key={item.id} value={item.id}>
{item.name}
</option>
))}
</select>
);
}

function Securities({
auth,
authInputRef,
group,
groups,
oauth,
onChange,
onGroupChange,
onSubmit,
operation,
}) {
const securityTypes = operation.prepareSecurity();
return Object.keys(securityTypes).map(type => {
return Object.keys(securityTypes).map((type, idx) => {
const securities = securityTypes[type];
return (
<form key={type} onSubmit={onSubmit}>
<h3>{`${type} Auth`}</h3>
<h3>
{`${type} Auth`}
{/* Only show the groups list for the first security (assuming there are multiple). */}
{idx === 0 && <GroupsList group={group} groups={groups} onGroupChange={onGroupChange} />}
</h3>
<div className="pad">
<section>
{
Expand Down Expand Up @@ -44,15 +78,18 @@ function Securities({ authInputRef, operation, onChange, oauth, auth, onSubmit }
}

function AuthBox({
auth,
authInputRef,
operation,
onSubmit,
group,
groups,
needsAuth,
oauth,
onChange,
onGroupChange,
onSubmit,
open,
needsAuth,
operation,
toggle,
oauth,
auth,
}) {
if (Object.keys(operation.prepareSecurity()).length === 0) return null;

Expand All @@ -67,8 +104,11 @@ function AuthBox({
<Securities
auth={auth}
authInputRef={authInputRef}
group={group}
groups={groups}
oauth={oauth}
onChange={onChange}
onGroupChange={onGroupChange}
onSubmit={e => {
e.preventDefault();
onSubmit();
Expand All @@ -87,7 +127,23 @@ function AuthBox({
);
}

const commonProps = {
group: PropTypes.string,
groups: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string,
name: PropTypes.string,
}),
),
onGroupChange: PropTypes.func.isRequired,
};

GroupsList.propTypes = {
...commonProps,
};

AuthBox.propTypes = {
...commonProps,
auth: PropTypes.shape({}),
authInputRef: PropTypes.func,
needsAuth: PropTypes.bool,
Expand Down
Loading