Skip to content

Commit

Permalink
Merge branch 'master' into errorCheckIds
Browse files Browse the repository at this point in the history
  • Loading branch information
nic-chen authored Dec 22, 2020
2 parents d560a5f + 97c5397 commit 8f799fc
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 6 deletions.
28 changes: 28 additions & 0 deletions docs/USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ The Route module aims to control routes by UI instead of calling APIs.

![route-create-done-list-en](./images/route-create-done-list-en.png)

### Online debug

We can debug a route both published or offline with the online debug function, which is located in the routes list page.

1. Debug a published route

![route-debug-published](./images/route-debug-published.png)

2. Debug a offline route

![route-debug-offline](./images/route-debug-offline.png)

3. Debug a published route with query params

![route-debug-query-params](./images/route-debug-query-params.png)

4. Debug a published route with header params

![route-debug-header-params](./images/route-debug-header-params.png)

5. Debug a published route with body params

![route-debug-body-params](./images/route-debug-body-params.png)

6. Debug a published route with basic auth

![route-debug-basic-auth](./images/route-debug-basic-auth.png)

## Setting

![setting](./images/setting-en.png)
Binary file added docs/images/route-debug-basic-auth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/route-debug-body-params.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/route-debug-header-params.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/route-debug-offline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/route-debug-published.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/route-debug-query-params.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.
*/
/* eslint-disable no-undef */

context('Create and Delete Consumer', () => {
const name = `consumerName${new Date().valueOf()}`;
const sleepTime = 100;
const domSelectors = {
notification: '.ant-notification-notice-message',
pluginsCard: '.ant-card'
};

beforeEach(() => {
// init login
cy.login();
})

it('creates consumer with key-auth', () => {
// go to consumer create page
cy.visit('/');
cy.contains('Consumer').click();
cy.wait(sleepTime * 5);
cy.contains('Create').click();

// Basic Information
cy.get('#username').type(name);
cy.get('#desc').type('desc_by_autotest');
cy.contains('Next').click();
cy.wait(sleepTime * 3);

// Plugin Config
cy.contains(domSelectors.pluginsCard, 'key-auth').within(() => {
cy.get('button').first().click();
})
// edit CodeMirror
cy.get('.CodeMirror')
.first()
.then((editor) => {
editor[0].CodeMirror.setValue(JSON.stringify({
"key": "test"
}));
cy.contains('button', 'Submit').click();
});
cy.contains('button', 'Next').click();
cy.contains('button', 'Submit').click();
});

it('delete the consumer', () => {
cy.visit('/');
cy.contains('Consumer').click();
cy.wait(sleepTime * 5)
cy.contains(name).siblings().contains('Delete').click();
cy.contains('button', 'Confirm').click();
cy.get(domSelectors.notification).should('contain', 'Delete Consumer Successfully');
});

it('creates consumer with wrong json', () => {
// go to consumer create page
cy.visit('/');
cy.contains('Consumer').click();
cy.wait(sleepTime * 5);
cy.contains('Create').click();

// Basic Information
cy.get('#username').type(name);
cy.get('#desc').type('desc_by_autotest');
cy.contains('Next').click();
cy.wait(sleepTime * 3);

// Plugin Config
cy.contains(domSelectors.pluginsCard, 'key-auth').within(() => {
cy.get('button').first().click();
})
// edit CodeMirror
cy.get('.CodeMirror')
.first()
.then((editor) => {
editor[0].CodeMirror.setValue(JSON.stringify({
"key_not_exst": "test"
}));
cy.contains('button', 'Submit').click();
});
cy.get(domSelectors.notification).should('contain', 'Invalid plugin data');
});
})
30 changes: 24 additions & 6 deletions web/src/pages/Route/components/DebugViews/DebugDrawView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
HTTP_METHOD_OPTION_LIST,
DEFAULT_DEBUG_PARAM_FORM_DATA,
DEFAULT_DEBUG_AUTH_FORM_DATA,
PROTOCOL_SUPPORTED,
} from '../../constants';
import { DebugParamsView, AuthenticationView } from '.';
import { debugRoute } from '../../service';
Expand All @@ -37,7 +38,8 @@ const { TabPane } = Tabs;

const DebugDrawView: React.FC<RouteModule.DebugDrawProps> = (props) => {
const { formatMessage } = useIntl();
const [httpMethod, setHttpMethod] = useState('GET');
const [httpMethod, setHttpMethod] = useState(HTTP_METHOD_OPTION_LIST[0]);
const [requestProtocol, setRequestProtocol] = useState(PROTOCOL_SUPPORTED[0])
const [showBodyTab, setShowBodyTab] = useState(false);
const [queryForm] = Form.useForm();
const [bodyForm] = Form.useForm();
Expand Down Expand Up @@ -79,7 +81,7 @@ const DebugDrawView: React.FC<RouteModule.DebugDrawProps> = (props) => {
) => {
let transformData = {};
(formData || [])
.filter((data) => data.check)
.filter((data) => data && data.check)
.forEach((data) => {
transformData = {
...transformData,
Expand Down Expand Up @@ -134,8 +136,8 @@ const DebugDrawView: React.FC<RouteModule.DebugDrawProps> = (props) => {
setLoading(true);
// TODO: grpc and websocket
debugRoute({
url: `${url}${urlQueryString && `?${urlQueryString}`}`,
request_protocol: 'http',
url: `${requestProtocol}://${url}${urlQueryString && `?${urlQueryString}`}`,
request_protocol: requestProtocol,
method: httpMethod,
body_params: bodyFormData,
header_params: headerFormData,
Expand All @@ -155,7 +157,7 @@ const DebugDrawView: React.FC<RouteModule.DebugDrawProps> = (props) => {
mask={false}
maskClosable={false}
visible={props.visible}
width={600}
width={650}
onClose={() => {
props.onClose();
}}
Expand All @@ -180,12 +182,28 @@ const DebugDrawView: React.FC<RouteModule.DebugDrawProps> = (props) => {
);
})}
</Select>
<Select
defaultValue={requestProtocol}
style={{ width: '18%' }}
onChange={(value) => {
setRequestProtocol(value);
}}
size="large"
>
{PROTOCOL_SUPPORTED.map((protocol) => {
return (
<Option key={protocol} value={protocol}>
{`${protocol}://`}
</Option>
);
})}
</Select>
<Search
placeholder={formatMessage({ id: 'page.route.input.placeholder.requestUrl' })}
allowClear
enterButton={formatMessage({ id: 'page.route.button.send' })}
size="large"
style={{ width: '80%' }}
style={{ width: '62%' }}
onSearch={handleDebug}
onPressEnter={(e) => {
handleDebug(e.currentTarget.value);
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/Route/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export const HASH_ON_LIST = ['vars', 'header', 'cookie', 'consumer'];

export const AUTH_LIST = ['basic-auth', 'jwt-auth', 'key-auth'];

export const PROTOCOL_SUPPORTED = ['http', 'https'];

export const DEFAULT_DEBUG_PARAM_FORM_DATA = {
params: [
{
Expand Down

0 comments on commit 8f799fc

Please sign in to comment.