SkyeYoung commented on code in PR #3245: URL: https://github.com/apache/apisix-dashboard/pull/3245#discussion_r2563849630
########## e2e/tests/secrets.crud-required-fields.spec.ts: ########## @@ -0,0 +1,148 @@ +/** + * 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. + */ +import { secretsPom } from '@e2e/pom/secrets'; +import { e2eReq } from '@e2e/utils/req'; +import { test } from '@e2e/utils/test'; +import { expect } from '@playwright/test'; + +import { API_SECRETS } from '@/config/constant'; + +let createdSecretId: string; Review Comment: ditto ########## e2e/tests/secrets.crud-all-fields.spec.ts: ########## @@ -0,0 +1,166 @@ +/** + * 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. + */ +import { secretsPom } from '@e2e/pom/secrets'; +import { e2eReq } from '@e2e/utils/req'; +import { test } from '@e2e/utils/test'; +import { expect } from '@playwright/test'; + +import { API_SECRETS } from '@/config/constant'; + + +let createdSecretId: string; +const manager = 'aws'; + +test.describe('CRUD secret with all fields (AWS)', () => { + test.describe.configure({ mode: 'serial' }); + + test.beforeAll(async () => { + createdSecretId = 'test-aws-secret-all-fields'; + }); + + test.afterAll(async () => { + // cleanup: delete the secret + if (createdSecretId) { + await e2eReq.delete(`${API_SECRETS}/${manager}/${createdSecretId}`).catch(() => { + // ignore error if secret doesn't exist + }); + } + }); + + test('should create a secret with all fields', async ({ page }) => { + await test.step('create secret via UI', async () => { + await secretsPom.toIndex(page); + await secretsPom.getAddSecretBtn(page).click(); + await secretsPom.isAddPage(page); + + await page.getByLabel('ID').fill(createdSecretId); + + // Select Manager AWS + const managerSection = page.getByRole('group', { name: 'Secret Manager' }); + await managerSection.locator('input.mantine-Select-input').click(); + await page.getByRole('option', { name: 'aws' }).click(); + + await page.getByLabel('Access Key ID').fill('AKIAIOSFODNN7EXAMPLE'); + await page.getByLabel('Secret Access Key').fill('wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'); + await page.getByLabel('Session Token').fill('test-session-token-123'); + await page.getByLabel('Region').fill('us-west-2'); + await page.getByLabel('Endpoint URL').fill('https://secretsmanager.us-west-2.amazonaws.com'); + + await secretsPom.getAddBtn(page).click(); + }); + + await test.step('verify secret appears in UI', async () => { + await secretsPom.isIndexPage(page); + const row = page.locator('tr').filter({ hasText: createdSecretId }); + await expect(row).toBeVisible(); + }); + }); + + test('should read/view the secret details', async ({ page }) => { + await test.step('navigate to secret details page and verify UI', async () => { + await secretsPom.toIndex(page); + await secretsPom.isIndexPage(page); + + const row = page.locator('tr').filter({ hasText: createdSecretId }); + await row.getByRole('button', { name: 'View' }).click(); + await secretsPom.isDetailPage(page); + + const pageContent = await page.textContent('body'); + expect(pageContent).toContain('Secret Manager'); + await expect(page.locator('input[name="id"]')).toHaveValue(createdSecretId); + // Verify AWS-specific fields are present (labels) + expect(pageContent).toContain('Access Key ID'); + expect(pageContent).toContain('Secret Access Key'); + expect(pageContent).toContain('Region'); + }); + }); + + test('should update the secret with new values', async ({ page }) => { + const updatedAccessKeyId = 'AKIAI44QH8DHBEXAMPLE'; + const updatedSecretAccessKey = 'je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY'; + const updatedSessionToken = 'updated-session-token-456'; + const updatedRegion = 'eu-west-1'; + const updatedEndpointUrl = 'https://secretsmanager.eu-west-1.amazonaws.com'; Review Comment: why repeat yourself? ########## e2e/tests/secrets.crud-all-fields.spec.ts: ########## @@ -0,0 +1,166 @@ +/** + * 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. + */ +import { secretsPom } from '@e2e/pom/secrets'; +import { e2eReq } from '@e2e/utils/req'; +import { test } from '@e2e/utils/test'; +import { expect } from '@playwright/test'; + +import { API_SECRETS } from '@/config/constant'; + + +let createdSecretId: string; +const manager = 'aws'; + +test.describe('CRUD secret with all fields (AWS)', () => { + test.describe.configure({ mode: 'serial' }); + + test.beforeAll(async () => { + createdSecretId = 'test-aws-secret-all-fields'; + }); + + test.afterAll(async () => { + // cleanup: delete the secret + if (createdSecretId) { + await e2eReq.delete(`${API_SECRETS}/${manager}/${createdSecretId}`).catch(() => { + // ignore error if secret doesn't exist Review Comment: why ingore? Please use AI only when you know why ########## e2e/tests/secrets.crud-all-fields.spec.ts: ########## @@ -0,0 +1,166 @@ +/** + * 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. + */ +import { secretsPom } from '@e2e/pom/secrets'; +import { e2eReq } from '@e2e/utils/req'; +import { test } from '@e2e/utils/test'; +import { expect } from '@playwright/test'; + +import { API_SECRETS } from '@/config/constant'; + + +let createdSecretId: string; Review Comment: why not const ########## e2e/tests/secrets.crud-required-fields.spec.ts: ########## @@ -0,0 +1,148 @@ +/** + * 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. + */ +import { secretsPom } from '@e2e/pom/secrets'; +import { e2eReq } from '@e2e/utils/req'; +import { test } from '@e2e/utils/test'; +import { expect } from '@playwright/test'; + +import { API_SECRETS } from '@/config/constant'; + +let createdSecretId: string; +const manager = 'vault'; + +test.describe('CRUD secret with required fields only (Vault)', () => { + test.describe.configure({ mode: 'serial' }); + + test.beforeAll(async () => { + createdSecretId = 'test-vault-secret-required'; + }); + + test.afterAll(async () => { + // cleanup: delete the secret + if (createdSecretId) { + await e2eReq.delete(`${API_SECRETS}/${manager}/${createdSecretId}`).catch(() => { + // ignore error if secret doesn't exist Review Comment: why ingore? ########## e2e/tests/secrets.crud-required-fields.spec.ts: ########## @@ -0,0 +1,148 @@ +/** + * 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. + */ +import { secretsPom } from '@e2e/pom/secrets'; +import { e2eReq } from '@e2e/utils/req'; +import { test } from '@e2e/utils/test'; +import { expect } from '@playwright/test'; + +import { API_SECRETS } from '@/config/constant'; + +let createdSecretId: string; +const manager = 'vault'; + +test.describe('CRUD secret with required fields only (Vault)', () => { + test.describe.configure({ mode: 'serial' }); + + test.beforeAll(async () => { + createdSecretId = 'test-vault-secret-required'; + }); + + test.afterAll(async () => { + // cleanup: delete the secret + if (createdSecretId) { + await e2eReq.delete(`${API_SECRETS}/${manager}/${createdSecretId}`).catch(() => { + // ignore error if secret doesn't exist + }); + } + }); + + test('should create a secret with required fields', async ({ page }) => { + await test.step('create secret via UI', async () => { + await secretsPom.toIndex(page); + await secretsPom.getAddSecretBtn(page).click(); + await secretsPom.isAddPage(page); + + await page.getByLabel('ID').fill(createdSecretId); + + // Vault is default + await page.getByLabel('URI').fill('http://vault.example.com:8200'); + await page.getByLabel('Prefix').fill('/secret/test'); + await page.getByLabel('Token').fill('test-vault-token-123'); + + await secretsPom.getAddBtn(page).click(); + }); + + await test.step('verify secret appears in UI', async () => { + await secretsPom.isIndexPage(page); + const row = page.locator('tr').filter({ hasText: createdSecretId }); + await expect(row).toBeVisible(); + }); + }); + + test('should read/view the secret details', async ({ page }) => { + await test.step('navigate to secret details page and verify UI', async () => { + await secretsPom.toIndex(page); + await secretsPom.isIndexPage(page); + + // Find and click the View button for the created secret + const row = page.locator('tr').filter({ hasText: createdSecretId }); + await row.getByRole('button', { name: 'View' }).click(); + await secretsPom.isDetailPage(page); + + // Assert Vault field values using input selectors + await expect(page.getByLabel('URI')).toHaveValue('http://vault.example.com:8200'); + await expect(page.getByLabel('Prefix')).toHaveValue('/secret/test'); + await expect(page.getByLabel('Token')).toHaveValue('test-vault-token-123'); Review Comment: why repeat yourself -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
