|
| 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 | + |
| 18 | +import { expect } from '@playwright/test'; |
| 19 | +import { test } from '@utils/test'; |
| 20 | + |
| 21 | +import { getAPISIXConf } from './utils/common'; |
| 22 | + |
| 23 | +// use empty storage state to avoid auth |
| 24 | +test.use({ storageState: { cookies: [], origins: [] } }); |
| 25 | + |
| 26 | +test('can auth with admin key', { tag: '@auth' }, async ({ page }) => { |
| 27 | + const settingsModal = page.getByRole('dialog', { name: 'Settings' }); |
| 28 | + const adminKeyInput = page.getByRole('textbox', { name: 'Admin Key' }); |
| 29 | + const failedMsg = page.getByText('failed to check token'); |
| 30 | + |
| 31 | + const checkSettingsModal = async () => { |
| 32 | + await expect(failedMsg).toBeVisible(); |
| 33 | + await expect(settingsModal).toBeVisible(); |
| 34 | + await expect(page.getByText('UI Commit SHA')).toBeVisible(); |
| 35 | + }; |
| 36 | + |
| 37 | + await test.step('fill wrong admin key, settings modal always be visible', async () => { |
| 38 | + await checkSettingsModal(); |
| 39 | + |
| 40 | + await expect(adminKeyInput).toBeEmpty(); |
| 41 | + await adminKeyInput.fill('wrong-admin-key'); |
| 42 | + await page |
| 43 | + .getByRole('dialog', { name: 'Settings' }) |
| 44 | + .getByRole('button') |
| 45 | + .click(); |
| 46 | + |
| 47 | + await page.reload(); |
| 48 | + await expect(failedMsg).toBeVisible(); |
| 49 | + await expect(settingsModal).toBeVisible(); |
| 50 | + }); |
| 51 | + |
| 52 | + await test.step('fill correct admin key, settings modal can be hidden', async () => { |
| 53 | + await page.reload(); |
| 54 | + await checkSettingsModal(); |
| 55 | + |
| 56 | + const { adminKey } = await getAPISIXConf(); |
| 57 | + await adminKeyInput.clear(); |
| 58 | + await adminKeyInput.fill(adminKey); |
| 59 | + await page |
| 60 | + .getByRole('dialog', { name: 'Settings' }) |
| 61 | + .getByRole('button') |
| 62 | + .click(); |
| 63 | + |
| 64 | + await page.reload(); |
| 65 | + await expect(failedMsg).toBeHidden(); |
| 66 | + }); |
| 67 | +}); |
0 commit comments