You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ma...@apache.org on 2021/05/18 09:36:48 UTC

[apisix-dashboard] branch master updated: fix: turn off online debug (#1903)

This is an automated email from the ASF dual-hosted git repository.

majunjie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 9728a43  fix: turn off online debug (#1903)
9728a43 is described below

commit 9728a430193331d135da4fd5661cd4100308afbf
Author: liuxiran <li...@apache.org>
AuthorDate: Tue May 18 17:36:39 2021 +0800

    fix: turn off online debug (#1903)
---
 .../route_online_debug/route_online_debug_test.go  |  97 -------
 api/internal/route.go                              |   2 -
 .../route_online_debug_suite_test.go               |   2 +-
 docs/en/latest/USER_GUIDE.md                       |  28 --
 web/cypress/integration/route/online-debug.spec.js | 322 ---------------------
 web/src/pages/Route/List.tsx                       |   8 +-
 6 files changed, 2 insertions(+), 457 deletions(-)

diff --git a/api/internal/handler/route_online_debug/route_online_debug_test.go b/api/internal/handler/route_online_debug/route_online_debug_test.go
deleted file mode 100644
index a049ef7..0000000
--- a/api/internal/handler/route_online_debug/route_online_debug_test.go
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.
- */
-
-package route_online_debug
-
-import (
-	"compress/gzip"
-	"github.com/shiningrush/droplet"
-	"github.com/shiningrush/droplet/data"
-	"github.com/stretchr/testify/assert"
-	"net/http"
-	"net/http/httptest"
-	"testing"
-)
-
-var TestResponse = "test"
-
-func mockServer() *httptest.Server {
-	f := func(w http.ResponseWriter, r *http.Request) {
-		w.Header().Add("Content-Type", "plain/text")
-		w.Header().Set("Content-Encoding", "gzip")
-		writer, _ := gzip.NewWriterLevel(w, gzip.BestCompression)
-		defer writer.Close()
-		_, _ = writer.Write([]byte(TestResponse))
-	}
-	return httptest.NewServer(http.HandlerFunc(f))
-}
-
-func TestHTTPProtocolSupport_RequestForwarding(t *testing.T) {
-	server := mockServer()
-	defer server.Close()
-	var cases = []struct {
-		Desc   string
-		Input  *DebugOnlineInput
-		Result interface{}
-	}{
-		{
-			Desc: "unsupported method",
-			Input: &DebugOnlineInput{
-				URL:    server.URL,
-				Method: "Lock",
-			},
-			Result: &data.SpecCodeResponse{StatusCode: http.StatusBadRequest},
-		},
-		{
-			Desc:   "wrong url",
-			Input:  &DebugOnlineInput{URL: "grpc://localhost"},
-			Result: &data.SpecCodeResponse{StatusCode: http.StatusBadRequest},
-		},
-		{
-			Desc: "not specify the accept-encoding request header explicitly",
-			Input: &DebugOnlineInput{
-				URL:          server.URL,
-				Method:       "Get",
-				HeaderParams: "{}",
-			},
-			Result: TestResponse,
-		},
-		{
-			Desc: "specify the accept-encoding request header explicitly",
-			Input: &DebugOnlineInput{
-				URL:          server.URL,
-				Method:       "Get",
-				HeaderParams: `{"Accept-Encoding": ["gzip"]}`,
-			},
-			Result: TestResponse,
-		},
-	}
-	for _, c := range cases {
-		t.Run(c.Desc, func(t *testing.T) {
-			proto := &HTTPProtocolSupport{}
-			context := droplet.NewContext()
-			context.SetInput(c.Input)
-			result, _ := proto.RequestForwarding(context)
-			switch result.(type) {
-			case *Result:
-				assert.Equal(t, result.(*Result).Data, c.Result.(string))
-			case *data.SpecCodeResponse:
-				assert.Equal(t, result, c.Result)
-			}
-		})
-	}
-}
diff --git a/api/internal/route.go b/api/internal/route.go
index ff101f0..c286743 100644
--- a/api/internal/route.go
+++ b/api/internal/route.go
@@ -35,7 +35,6 @@ import (
 	"github.com/apisix/manager-api/internal/handler/label"
 	"github.com/apisix/manager-api/internal/handler/plugin_config"
 	"github.com/apisix/manager-api/internal/handler/route"
-	"github.com/apisix/manager-api/internal/handler/route_online_debug"
 	"github.com/apisix/manager-api/internal/handler/schema"
 	"github.com/apisix/manager-api/internal/handler/server_info"
 	"github.com/apisix/manager-api/internal/handler/service"
@@ -70,7 +69,6 @@ func SetUpRouter() *gin.Engine {
 		healthz.NewHandler,
 		authentication.NewHandler,
 		global_rule.NewHandler,
-		route_online_debug.NewHandler,
 		server_info.NewHandler,
 		label.NewHandler,
 		data_loader.NewHandler,
diff --git a/api/test/e2enew/route_online_debug/route_online_debug_suite_test.go b/api/test/e2enew/route_online_debug/route_online_debug_suite_test.go
index 06b97a0..219d8d3 100644
--- a/api/test/e2enew/route_online_debug/route_online_debug_suite_test.go
+++ b/api/test/e2enew/route_online_debug/route_online_debug_suite_test.go
@@ -28,7 +28,7 @@ import (
 
 func TestRoute(t *testing.T) {
 	gomega.RegisterFailHandler(ginkgo.Fail)
-	ginkgo.RunSpecs(t, "route online debug suite")
+	//ginkgo.RunSpecs(t, "route online debug suite")
 }
 
 var _ = ginkgo.AfterSuite(func() {
diff --git a/docs/en/latest/USER_GUIDE.md b/docs/en/latest/USER_GUIDE.md
index b37b4e9..9058cd9 100644
--- a/docs/en/latest/USER_GUIDE.md
+++ b/docs/en/latest/USER_GUIDE.md
@@ -49,34 +49,6 @@ The Route module aims to control routes by UI instead of calling APIs.
 
 ![route-create-done-list-en](https://user-images.githubusercontent.com/40708551/112923280-a0a94080-912b-11eb-8b83-3960778ecf8a.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](../../assets/images/route-debug-published.png)
-
-2. Debug a offline route
-
-![route-debug-offline](https://user-images.githubusercontent.com/40708551/112923419-e5cd7280-912b-11eb-8e7e-57c3c4fe31ef.png)
-
-3. Debug a published route with query params
-
-![route-debug-query-params](../../assets/images/route-debug-query-params.png)
-
-4. Debug a published route with header params
-
-![route-debug-header-params](../../assets/images/route-debug-header-params.png)
-
-5. Debug a published route with body params
-
-![route-debug-body-params](../../assets/images/route-debug-body-params.png)
-
-6. Debug a published route with basic auth
-
-![route-debug-basic-auth](../../assets/images/route-debug-basic-auth.png)
-
 ## Setting
 
 ![setting](https://user-images.githubusercontent.com/40708551/112923561-22996980-912c-11eb-926f-45177500eb65.png)
diff --git a/web/cypress/integration/route/online-debug.spec.js b/web/cypress/integration/route/online-debug.spec.js
deleted file mode 100644
index 559c24a..0000000
--- a/web/cypress/integration/route/online-debug.spec.js
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * 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 */
-import menuLocaleUS from '../../../src/locales/en-US/menu';
-import routeLocaleUS from '../../../src/pages/Route/locales/en-US';
-import defaultSettings from '../../../config/defaultSettings';
-
-context('Online debug', () => {
-  const { SERVE_ENV = 'dev' } = Cypress.env();
-
-  const selector = {
-    refresh: '.anticon-reload',
-    debugUri: '#debugUri',
-    debugDraw: '[data-cy=debug-draw]',
-    deubugMethod: '[data-cy=debug-method]',
-    debugProtocol: '[data-cy=debug-protocol]',
-    debugFormDataKey0: '#dynamic_form_data_item_params_0_key',
-    debugFormDataType0: '[data-cy=debug-formdata-type-0]',
-    debugFormDataValue0: '#dynamic_form_data_item_params_0_value',
-    debugFormDataFileButton0: '[data-cy=debug-upload-btn-0]',
-    codeMirrorResp: '#codeMirror-response',
-    headerDataKey0: '#headerForm_params_0_key',
-    headerDataValue0: '#headerForm_params_0_value',
-    queryDataKey0: '#queryForm_params_0_key',
-    queryDataValue0: '#queryForm_params_0_value',
-    queryTab: '#rc-tabs-0-tab-query',
-    authTab: '#rc-tabs-0-tab-auth',
-    headerTab: '#rc-tabs-0-tab-header',
-    bodyTab: '#rc-tabs-0-tab-body',
-    jwtAuth: '[data-cy=jwt-auth]',
-    jwtTokenInput: '#authForm_Authorization',
-    drawerClose: '.ant-drawer-close',
-    notification: '.ant-notification-notice-message',
-    notificationCloseIcon: '.ant-notification-close-icon',
-    deleteAlert: '.ant-modal-body',
-  };
-
-  const data = {
-    deleteRouteSuccess: 'Delete Route Successfully',
-    validUris: [
-      'localhost:9000/get',
-      '127.0.0.1:9000/get',
-      'www.baidu.com/get',
-      'baidu.com/get',
-      'test-host.com/get',
-      'test-host.com/aBCdsf/defsdf456eweWQE',
-      'localhost:9000/deps-get',
-      'localhost:9000/deps.get',
-      'localhost:9000/deps_get',
-      'localhost:9000/get?search=1',
-      'localhost:9000/get?search=v1,sd&number=-1',
-      'localhost:9000/get?search=1+1',
-      'localhost:9000/api/commands/submit.html#Requirements?test=apisix.com',
-      'localhost:9000/js6/main.jsp?sid=pARQZYHABxkSVdeMvXAAEtfJKbWQocOA&df=mail126_mailmaster#module=mbox.ListModule%7C%7B',
-    ],
-    invalidUrls: ['000'],
-    postFileUrl: `${
-      defaultSettings.serveUrlMap[SERVE_ENV].split('//')[1]
-    }/apisix/admin/import/routes`,
-    routeOptUrl: `${defaultSettings.serveUrlMap[SERVE_ENV].split('//')[1]}/apisix/admin/routes`,
-    uploadFile: '../../../api/test/testdata/import/default.json',
-    headerAuthorizationKey: 'Authorization',
-    routeName: 'hello',
-    queryKey0: 'name',
-  };
-
-  beforeEach(() => {
-    cy.login();
-
-    cy.fixture('route-json-data.json').as('routeData');
-    cy.intercept('/apisix/admin/debug-request-forwarding').as('DebugAPI');
-  });
-
-  it('should not show the invalid url notification', function () {
-    cy.visit('/');
-    cy.contains(menuLocaleUS['menu.routes']).click();
-
-    // show online debug draw
-    cy.get(selector.refresh).click();
-    cy.contains('Advanced').click();
-    cy.contains(routeLocaleUS['page.route.onlineDebug']).click();
-    cy.get(selector.debugDraw).should('be.visible');
-    // input uri with specified special characters
-    data.validUris.forEach((uri) => {
-      cy.get(selector.debugUri).clear();
-      cy.get(selector.debugUri).type(uri);
-      cy.contains(routeLocaleUS['page.route.button.send']).click({ force: true });
-
-      // should not show the notification about input the valid request url
-      cy.contains(routeLocaleUS['page.route.input.placeholder.requestUrl']).should('not.exist');
-    });
-  });
-
-  it('should show the invalid url notification', function () {
-    cy.visit('/');
-    cy.contains(menuLocaleUS['menu.routes']).click();
-
-    // show online debug draw
-    cy.get(selector.refresh).click();
-    cy.contains('Advanced').click();
-    cy.contains(routeLocaleUS['page.route.onlineDebug']).click();
-    cy.get(selector.debugDraw).should('be.visible');
-
-    // click send without type debugUrl
-    cy.contains(routeLocaleUS['page.route.button.send']).click({ force: true });
-    cy.contains(routeLocaleUS['page.route.input.placeholder.requestUrl']).should('exist');
-    cy.get(selector.notificationCloseIcon).click({ multiple: true });
-
-    // input invalid uris
-    data.invalidUrls.forEach((uri) => {
-      cy.get(selector.debugUri).clear();
-      cy.get(selector.debugUri).type(uri);
-      cy.contains(routeLocaleUS['page.route.button.send']).click({ force: true });
-
-      // should not show the notification about input the valid request url
-      cy.contains(routeLocaleUS['page.route.input.placeholder.requestUrl']).should('exist');
-      cy.get(selector.notificationCloseIcon).click({ multiple: true });
-    });
-  });
-
-  it('should autocomplete header', function () {
-    cy.visit('/');
-    cy.contains(menuLocaleUS['menu.routes']).click();
-    const currentToken = localStorage.getItem('token');
-
-    // show online debug draw
-    cy.get(selector.refresh).click();
-    cy.contains('Advanced').click();
-    cy.contains(routeLocaleUS['page.route.onlineDebug']).click();
-    cy.get(selector.debugDraw).should('be.visible');
-    cy.get(selector.headerTab).should('be.visible').click();
-
-    // show autocomplete
-    cy.get(selector.headerDataKey0).click({ force: true });
-    cy.get('.ant-select-item-option-content').contains('Accept').click();
-    cy.get('.anticon-minus-circle').click();
-
-    // autocomplete should ingore case
-    cy.get(selector.headerDataKey0).type('auth').click({ force: true });
-    cy.get('.ant-select-item-option-content').contains('Authorization').click();
-    cy.get(selector.headerDataValue0).type(currentToken);
-  });
-
-  it('should debug POST request with file successfully', function () {
-    cy.visit('/');
-    cy.contains(menuLocaleUS['menu.routes']).click();
-    const currentToken = localStorage.getItem('token');
-
-    // show online debug draw
-    cy.get(selector.refresh).click();
-    cy.contains('Advanced').click();
-    cy.contains(routeLocaleUS['page.route.onlineDebug']).click();
-    cy.get(selector.debugDraw).should('be.visible');
-
-    // change request method POST
-    cy.get(selector.deubugMethod).click();
-    cy.get('[title=POST]').click();
-
-    // change request protocol http
-    cy.get(selector.debugProtocol).click();
-    cy.contains('http://').click();
-    // set debug uri
-    cy.get(selector.debugUri).type(data.postFileUrl);
-    // set request body
-    cy.get(selector.bodyTab).should('be.visible').click();
-
-    cy.contains('form-data').should('be.visible').click();
-    cy.get(selector.debugFormDataKey0).type('file');
-
-    // check change type
-    cy.get(selector.debugFormDataType0).click();
-    cy.contains('Text').click();
-    // assert: text input dom should be visible
-    cy.get(selector.debugFormDataValue0).should('be.visible');
-    cy.get(selector.debugFormDataType0).click();
-    cy.contains('File').click();
-    // assert: upload file button should be visible
-    cy.get(selector.debugFormDataFileButton0).should('be.visible');
-    // attach file
-    cy.get(selector.debugFormDataValue0).attachFile(data.uploadFile);
-
-    // set header Authorization
-    cy.get(selector.headerTab).should('be.visible').click();
-    cy.get(selector.headerDataKey0).type(data.headerAuthorizationKey);
-    cy.get(selector.headerDataValue0).type(currentToken);
-
-    cy.contains(routeLocaleUS['page.route.button.send']).click();
-
-    cy.wait('@DebugAPI');
-    // assert: send request return
-    cy.get(selector.codeMirrorResp).contains('data').should('be.visible');
-    cy.get(selector.codeMirrorResp).contains('routes').should('be.visible');
-
-    // close debug drawer
-    cy.get(selector.drawerClose).click();
-  });
-
-  it('should debug GET request with query parammeters and jwt auth successfully', function () {
-    cy.visit('/');
-    cy.contains(menuLocaleUS['menu.routes']).click();
-    const currentToken = localStorage.getItem('token');
-
-    // show online debug draw
-    cy.get(selector.refresh).click();
-    cy.contains('Advanced').click();
-    cy.contains(routeLocaleUS['page.route.onlineDebug']).click();
-    cy.get(selector.debugDraw).should('be.visible');
-    // set debug uri
-    cy.get(selector.debugUri).type(data.routeOptUrl);
-    cy.get(selector.bodyTab).should('not.exist');
-    // set query param
-    cy.get(selector.queryDataKey0).type(data.queryKey0);
-    cy.get(selector.queryDataValue0).type(data.routeName);
-    // set Authentication
-    cy.get(selector.authTab).should('be.visible').click();
-    cy.get(selector.jwtAuth).click();
-    cy.get(selector.jwtTokenInput).should('be.visible').type(currentToken);
-
-    cy.contains(routeLocaleUS['page.route.button.send']).click();
-    cy.wait('@DebugAPI');
-    cy.get(selector.codeMirrorResp).within(() => {
-      cy.get('.cm-property').should(($property) => {
-        $property.map((i, el) => {
-          if (Cypress.$(el).text() === '"name"') {
-            const findRouteName = Cypress.$(el).next().text();
-            expect(findRouteName).to.equal('"hello"');
-          }
-          if (Cypress.$(el).text() === '"total_size"') {
-            const findTotalNumber = Cypress.$(el).next().text();
-            expect(findTotalNumber).to.equal('1');
-          }
-        });
-      });
-    });
-  });
-
-  it('should debug POST request with raw json successfully', function () {
-    cy.visit('/');
-    cy.contains(menuLocaleUS['menu.routes']).click();
-    const currentToken = localStorage.getItem('token');
-
-    // show online debug draw
-    cy.get(selector.refresh).click();
-    cy.contains('Advanced').click();
-    cy.contains(routeLocaleUS['page.route.onlineDebug']).click();
-    cy.get(selector.debugDraw).should('be.visible');
-
-    // change request method POST
-    cy.get(selector.deubugMethod).click();
-    cy.get('[title=POST]').click();
-
-    // change request protocol http
-    cy.get(selector.debugProtocol).click();
-    cy.contains('http://').click();
-    // set debug uri
-    cy.get(selector.debugUri).type(data.routeOptUrl);
-    // set Authentication
-    cy.get(selector.authTab).should('be.visible').click();
-    cy.get(selector.jwtAuth).click();
-    cy.get(selector.jwtTokenInput).should('be.visible').type(currentToken);
-
-    cy.get(selector.bodyTab).should('be.visible').click();
-
-    cy.contains('raw input').should('be.visible').click();
-
-    cy.window().then(({ codeMirrorBody }) => {
-      if (codeMirrorBody) {
-        codeMirrorBody.setValue(JSON.stringify(this.routeData.debugPostJson));
-      }
-      cy.contains(routeLocaleUS['page.route.button.send']).click();
-    });
-    cy.wait('@DebugAPI');
-    cy.get(selector.codeMirrorResp).contains('code').should('be.visible');
-    cy.get(selector.codeMirrorResp).within(() => {
-      cy.get('.cm-property').should(($property) => {
-        $property.map((i, el) => {
-          if (Cypress.$(el).text() === '"name"') {
-            const findRouteName = Cypress.$(el).next().text();
-            expect(findRouteName).to.equal(`"${this.routeData.debugPostJson.name}"`);
-          }
-          if (Cypress.$(el).text() === '"data"') {
-            const data = Cypress.$(el).next().text();
-            expect(data).to.not.equal('null');
-          }
-        });
-      });
-    });
-  });
-
-  it('should delete routes create for test cases successfully', function () {
-    cy.visit('/');
-    cy.contains(menuLocaleUS['menu.routes']).click();
-
-    const testRouteNames = [data.routeName, this.routeData.debugPostJson.name];
-    for (let routeName in testRouteNames) {
-      cy.contains(`${testRouteNames[routeName]}`).siblings().contains('More').click();
-      cy.contains('Delete').click({ force: true });
-      cy.get(selector.deleteAlert)
-        .should('be.visible')
-        .within(() => {
-          cy.contains('OK').click();
-        });
-      cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
-      cy.get(selector.notificationCloseIcon).click({ multiple: true });
-      cy.reload();
-    }
-  });
-});
diff --git a/web/src/pages/Route/List.tsx b/web/src/pages/Route/List.tsx
index c70622b..203213c 100644
--- a/web/src/pages/Route/List.tsx
+++ b/web/src/pages/Route/List.tsx
@@ -35,7 +35,7 @@ import {
   Dropdown,
 } from 'antd';
 import { history, useIntl } from 'umi';
-import { PlusOutlined, BugOutlined, ExportOutlined, ImportOutlined, DownOutlined } from '@ant-design/icons';
+import { PlusOutlined, ExportOutlined, ImportOutlined, DownOutlined } from '@ant-design/icons';
 import { js_beautify } from 'js-beautify';
 import yaml from 'js-yaml';
 import moment from 'moment';
@@ -204,12 +204,6 @@ const Page: React.FC = () => {
           setUploadFileList([]);
           setShowImportModal(true);
         }
-      }, {
-        name: formatMessage({ id: 'page.route.onlineDebug' }),
-        icon: <BugOutlined />,
-        onClick: () => {
-          setDebugDrawVisible(true)
-        }
       }
     ]