Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Fix jwks and formatOriginalToken issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasponce committed May 26, 2020
1 parent ef9b6db commit c1c82a5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/pages/IstioConfigNew/RequestAuthenticationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class RequestAuthenticationForm extends React.Component<Props, RequestAuthentica
};

onAddJwtRule = (jwtRule: JWTRule) => {
console.log('TODELETE onAddJwtRule');
console.log(jwtRule);

This comment has been minimized.

Copy link
@xeviknal

xeviknal May 26, 2020

Member

I guess you wanted to remove this

This comment has been minimized.

Copy link
@lucasponce

lucasponce May 26, 2020

Author Contributor

Ops, my bad, the old classic way to debug things when you find something odd :-)

this.setState(
(prevState) => {
prevState.jwtRules.push(jwtRule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PlusCircleIcon } from '@patternfly/react-icons';
import { TextInputBase as TextInput } from '@patternfly/react-core/dist/js/components/TextInput/TextInput';
import { style } from 'typestyle';
import { PfColors } from '../../../components/Pf/PfColors';
import { isValidUrl } from '../../../utils/IstioConfigUtils';

type Props = {
onAddJwtRule: (rule: JWTRule) => void;
Expand Down Expand Up @@ -83,7 +84,7 @@ export const formatJwtField = (jwtField: string, jwtRule: JWTRule): string => {
case 'outputPayloadToHeader':
return jwtRule.outputPayloadToHeader ? jwtRule.outputPayloadToHeader : '';
case 'forwardOriginalToken':
return jwtRule.forwardOriginalToken ? '' + jwtRule.forwardOriginalToken : '';
return jwtRule.forwardOriginalToken ? '' + jwtRule.forwardOriginalToken : 'false';
default:
}
return '';
Expand Down Expand Up @@ -216,6 +217,9 @@ class JwtRuleBuilder extends React.Component<Props, State> {
if (isEmptyValue) {
return [false, 'Value cannot be empty'];
}
if (this.state.newJwtField === 'jwksUri' && !isValidUrl(this.state.newValues)) {
return [false, 'jwsUri is not a valid Uri'];
}
return [true, ''];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class JwtRuleList extends React.Component<Props> {
<b>audiences</b>: [{formatJwtField('audiences', jwtRule)}]
</div>
) : undefined}
{jwtRule.jwks ? (
<div>
<b>jwks</b>: [{formatJwtField('jwks', jwtRule)}]
</div>
) : undefined}
{jwtRule.jwksUri ? (
<div>
<b>jwksUri</b>: [{formatJwtField('jwksUri', jwtRule)}]
Expand All @@ -66,7 +71,7 @@ class JwtRuleList extends React.Component<Props> {
<b>outputPayloadToHeader</b>: [{formatJwtField('outputPayloadToHeader', jwtRule)}]
</div>
) : undefined}
{jwtRule.forwardOriginalToken ? (
{jwtRule.forwardOriginalToken !== undefined ? (
<div>
<b>forwardOriginalToken</b>: [{formatJwtField('forwardOriginalToken', jwtRule)}]
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/utils/IstioConfigUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,12 @@ export const isServerHostValid = (serverHost: string, nsMandatory: boolean): boo
export const isValidIp = (ip: string): boolean => {
return ipRegexp.test(ip);
};

export const isValidUrl = (url: string): boolean => {
try {
new URL(url);
} catch (_) {
return false;
}
return true;
};
14 changes: 13 additions & 1 deletion src/utils/__tests__/IstioConfigUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isServerHostValid, mergeJsonPatch } from '../IstioConfigUtils';
import { isServerHostValid, isValidUrl, mergeJsonPatch } from '../IstioConfigUtils';

describe('Validate JSON Patchs', () => {
const gateway: object = {
Expand Down Expand Up @@ -83,3 +83,15 @@ describe('Validate Gateway/Sidecar Server Host ', () => {
expect(isServerHostValid('bookinf*/reviews', true)).toBeFalsy();
});
});

describe('Validate bad urls', () => {
it('Good urls', () => {
expect(isValidUrl('http://www.googleapis.com/oauth2/v1/certs')).toBeTruthy();
expect(isValidUrl('https://www.googleapis.com/oauth2/v1/certs')).toBeTruthy();
});

it('Bad urls', () => {
expect(isValidUrl('ramdom')).toBeFalsy();
expect(isValidUrl('123test')).toBeFalsy();
});
});

0 comments on commit c1c82a5

Please sign in to comment.