create-route-with-referer-restriction-form.cy.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* eslint-disable no-undef */
  18. context('Create and delete route with referer-restriction form', () => {
  19. const selector = {
  20. empty: '.ant-empty-normal',
  21. name: '#name',
  22. description: '#desc',
  23. pluginCardBordered: '.ant-card-bordered',
  24. nodes_0_host: '#submitNodes_0_host',
  25. nodes_0_port: '#submitNodes_0_port',
  26. nodes_0_weight: '#submitNodes_0_weight',
  27. disabledSwitcher: '#disable',
  28. checkedSwitcher: '.ant-switch-checked',
  29. drawer: '.ant-drawer-content',
  30. notification: '.ant-notification-notice-message',
  31. notificationCloseIcon: '.ant-notification-close-icon',
  32. deleteAlert: '.ant-modal-body',
  33. whitelist: '#whitelist_0',
  34. whitelist_1: '#whitelist_1',
  35. blacklist: '#blacklist_0',
  36. blacklist_1: '#blacklist_1',
  37. alert: '.ant-form-item-explain-error [role=alert]',
  38. newAddWhitelist: '[data-cy=addWhitelist]',
  39. newAddBlacklist: '[data-cy=addBlacklist]',
  40. passSwitcher: '#bypass_missing',
  41. };
  42. const data = {
  43. ip1: '127.0.0.1',
  44. port: '80',
  45. weight: 1,
  46. deleteRouteSuccess: 'Delete Route Successfully',
  47. submitSuccess: 'Submit Successfully',
  48. wrongIp: 'qq@',
  49. correctIp: 'apisix-dashboard_1.com',
  50. activeClass: 'ant-switch-checked',
  51. };
  52. beforeEach(() => {
  53. cy.login();
  54. });
  55. it('should create route with referer-restriction form', function () {
  56. cy.visit('/');
  57. cy.contains('Route').click();
  58. cy.get(selector.empty).should('be.visible');
  59. cy.contains('Create').click();
  60. cy.contains('Next').click().click();
  61. cy.get(selector.name).type('routeName');
  62. cy.get(selector.description).type('desc');
  63. cy.contains('Next').click();
  64. cy.get(selector.nodes_0_host).type(data.ip1);
  65. cy.get(selector.nodes_0_port).clear().type(data.port);
  66. cy.get(selector.nodes_0_weight).clear().type(data.weight);
  67. cy.contains('Next').click();
  68. // config referer-restriction plugin
  69. cy.contains('referer-restriction')
  70. .parents(selector.pluginCardBordered)
  71. .within(() => {
  72. cy.get('button').click({
  73. force: true,
  74. });
  75. });
  76. cy.get(selector.drawer)
  77. .should('be.visible')
  78. .within(() => {
  79. cy.get(selector.disabledSwitcher).click();
  80. cy.get(selector.disabledSwitcher).should('have.class', data.activeClass);
  81. cy.get(selector.passSwitcher).should('not.have.class', data.activeClass);
  82. });
  83. // config referer-restriction form without whitelist
  84. cy.get(selector.whitelist).click();
  85. cy.get(selector.drawer).within(() => {
  86. cy.contains('Submit').click({
  87. force: true,
  88. });
  89. });
  90. cy.get(selector.notification).should('contain', 'Invalid plugin data');
  91. cy.get(selector.notificationCloseIcon).click({ multiple: true });
  92. // config referer-restriction form with whitelist
  93. cy.get(selector.whitelist).type(data.wrongIp);
  94. cy.get(selector.whitelist).closest('div').next().children('span').should('exist');
  95. cy.get(selector.alert).should('exist');
  96. cy.get(selector.whitelist).clear().type(data.correctIp);
  97. cy.get(selector.alert).should('not.exist');
  98. cy.get(selector.newAddWhitelist).click();
  99. cy.get(selector.whitelist).closest('div').next().children('span').should('exist');
  100. cy.get(selector.whitelist_1).closest('div').next().children('span').should('exist');
  101. cy.get(selector.whitelist_1).type(data.correctIp);
  102. cy.get(selector.alert).should('not.exist');
  103. cy.get(selector.disabledSwitcher).click();
  104. cy.get(selector.drawer).within(() => {
  105. cy.contains('Submit').click({
  106. force: true,
  107. });
  108. });
  109. cy.get(selector.drawer).should('not.exist');
  110. // reopen plugin drawer for blacklist test
  111. cy.contains('referer-restriction')
  112. .parents(selector.pluginCardBordered)
  113. .within(() => {
  114. cy.get('button').click({
  115. force: true,
  116. });
  117. });
  118. cy.get(selector.drawer)
  119. .should('be.visible')
  120. .within(() => {
  121. cy.get(selector.disabledSwitcher).click();
  122. cy.get(selector.disabledSwitcher).should('have.class', data.activeClass);
  123. cy.get(selector.passSwitcher).should('not.have.class', data.activeClass);
  124. });
  125. cy.get(selector.blacklist).type(data.correctIp);
  126. cy.get(selector.newAddBlacklist).click();
  127. cy.get(selector.blacklist_1).type(data.correctIp);
  128. cy.get(selector.drawer).within(() => {
  129. cy.contains('Submit').click({
  130. force: true,
  131. });
  132. });
  133. cy.get(selector.notification).should('contain', 'Invalid plugin data');
  134. cy.get(selector.notificationCloseIcon).click({ multiple: true });
  135. cy.get(selector.whitelist).closest('div').next().children('span').click();
  136. cy.get(selector.whitelist).closest('div').next().children('span').click();
  137. cy.get(selector.drawer).within(() => {
  138. cy.contains('Submit').click({
  139. force: true,
  140. });
  141. });
  142. cy.get(selector.drawer).should('not.exist');
  143. // create route
  144. cy.contains('button', 'Next').click();
  145. cy.contains('button', 'Submit').click();
  146. cy.contains(data.submitSuccess);
  147. // back to route list page
  148. cy.contains('Goto List').click();
  149. cy.url().should('contains', 'routes/list');
  150. });
  151. it('should delete the route', function () {
  152. cy.get(selector.name).clear().type('routeName');
  153. cy.contains('Search').click();
  154. cy.contains('routeName').siblings().contains('More').click();
  155. cy.contains('Delete').click();
  156. cy.get(selector.deleteAlert)
  157. .should('be.visible')
  158. .within(() => {
  159. cy.contains('OK').click();
  160. });
  161. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  162. cy.get(selector.notificationCloseIcon).click();
  163. });
  164. });