Skip to content

Modern Docker Management, Designed for Everyone

fix(environments): allow token re-entry when changing agent API URL (#4160)

Kyle Mendellaf4dab5f0098
diff --git a/backend/internal/environment/service_test.go b/backend/internal/environment/service_test.go
index 1f9e04f2c..f65722c2d 100644
--- a/backend/internal/environment/service_test.go
+++ b/backend/internal/environment/service_test.go
@@ -789,21 +789,36 @@ func TestEnvironmentServiceUpdateEnvironmentRejectsTargetChangeWithStoredTokenIn
require.Equal(t, oldToken, *stored.AccessToken)
}
-func TestEnvironmentServiceUpdateEnvironmentAllowsTargetChangeWithReplacementTokenInternal(t *testing.T) {
- ctx := context.Background()
- db := setupEnvironmentServiceTestDB(t)
- svc := NewEnvironmentService(db, nil, nil, nil, nil, nil)
-
- oldToken := "stored-agent-token"
- createTestEnvironment(t, db, "env-target", "http://agent.example:3553", &oldToken)
+func TestEnvironmentServiceUpdateEnvironmentAllowsTargetChangeWithExplicitTokenInternal(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ token string
+ }{
+ {name: "reenter existing token", token: "stored-agent-token"},
+ {name: "use replacement token", token: "replacement-agent-token"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ ctx := t.Context()
+ db := setupEnvironmentServiceTestDB(t)
+ svc := NewEnvironmentService(db, nil, nil, nil, nil, nil)
+
+ oldToken := "stored-agent-token"
+ createTestEnvironment(t, db, "env-target", "http://agent.example:3553", &oldToken)
+
+ updated, err := svc.UpdateEnvironment(ctx, "env-target", map[string]any{
+ "api_url": "http://replacement.example:3553",
+ "access_token": tc.token,
+ }, nil, nil)
+ require.NoError(t, err)
+ require.Equal(t, "http://replacement.example:3553", updated.ApiUrl)
+ require.Equal(t, tc.token, *updated.AccessToken)
- updated, err := svc.UpdateEnvironment(ctx, "env-target", map[string]any{
- "api_url": "http://replacement.example:3553",
- "access_token": "replacement-agent-token",
- }, nil, nil)
- require.NoError(t, err)
- require.Equal(t, "http://replacement.example:3553", updated.ApiUrl)
- require.Equal(t, "replacement-agent-token", *updated.AccessToken)
+ var stored Environment
+ require.NoError(t, db.WithContext(ctx).First(&stored, "id = ?", "env-target").Error)
+ require.Equal(t, updated.ApiUrl, stored.ApiUrl)
+ require.Equal(t, tc.token, *stored.AccessToken)
+ })
+ }
}
func TestEnvironmentService_getCachedEnvironmentIDForTokenInternal_ExpiresAndCleansReverseIndex(t *testing.T) {
diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index ce4ea3053..8ad023125 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -1413,6 +1413,8 @@
"environments_test_connection_error": "Connection failed",
"environments_testing_connection": "Testing Connection…",
"environments_api_url": "API URL",
+ "environments_access_token_for_url_label": "Agent access token",
+ "environments_access_token_for_url_help": "Re-enter the agent's existing access token to save the new API URL. You don't need to rotate it.",
"environments_created_success": "Environment created successfully",
"environments_delete_message": "Are you sure you want to delete environment {name}?",
"environments_delete_failed": "Failed to delete environment {name}",
diff --git a/frontend/src/lib/types/environment.ts b/frontend/src/lib/types/environment.ts
index 3989cf2ae..6959f549b 100644
--- a/frontend/src/lib/types/environment.ts
+++ b/frontend/src/lib/types/environment.ts
@@ -39,6 +39,7 @@ export interface CreateEnvironmentDTO {
export interface UpdateEnvironmentDTO {
apiUrl?: string;
+ accessToken?: string;
name?: string;
enabled?: boolean;
isEdge?: boolean;
diff --git a/frontend/src/routes/(app)/environments/[id]/+page.svelte b/frontend/src/routes/(app)/environments/[id]/+page.svelte
index 9a0c2d15f..4261cf013 100644
--- a/frontend/src/routes/(app)/environments/[id]/+page.svelte
+++ b/frontend/src/routes/(app)/environments/[id]/+page.svelte
@@ -2,6 +2,7 @@
import type { Settings } from '#lib/types/settings.js';
import SectionCard from '#lib/components/section-card.svelte';
import LabeledSwitch from '#lib/components/form/labeled-switch.svelte';
+ import TextInputWithLabel from '#lib/components/form/text-input-with-label.svelte';
import { featureStore } from '#lib/stores/features.store.svelte.js';
import { tryCatch } from '#lib/utils/try-catch.js';
@@ -16,7 +17,7 @@
import { Input } from '#lib/components/ui/input/index.js';
import { CopyButton } from '#lib/components/ui/copy-button/index.js';
import { cn } from '#lib/utils.js';
- import { goto, refreshAll } from '$app/navigation';
+ import { beforeNavigate, goto, refreshAll } from '$app/navigation';
import { toast } from 'svelte-sonner';
import { m } from '#lib/paraglide/messages.js';
import { environmentManagementService } from '#lib/services/env-mgmt-service.js';
@@ -36,7 +37,11 @@
import StorageTab from './components/StorageTab.svelte';
import DockerTab from './components/DockerTab.svelte';
import JobsTab from './components/JobsTab.svelte';
- import { environmentFormSchema, type EnvironmentFormValues } from './components/environment-form-schema';
+ import {
+ environmentFormSchema,
+ environmentUpdateSchema,
+ type EnvironmentFormValues
+ } from './components/environment-form-schema';
import TrivySecuritySettings from '#lib/components/settings/trivy-security-settings.svelte';
import ImagePatchSettings from '#lib/components/settings/image-patch-settings.svelte';
import LifecycleSecuritySettings from '#lib/components/settings/lifecycle-security-settings.svelte';
@@ -61,7 +66,8 @@
let { data } = $props();
let { settings, versionInformation } = $derived(data);
let lastEnvironment: Environment | undefined;
- let environment = $derived((lastEnvironment = data.environment ?? lastEnvironment));
+ let loadedEnvironment = $derived((lastEnvironment = data.environment ?? lastEnvironment));
+ let environment = $derived(loadedEnvironment);
let refreshedEnvironment: Environment | null = $state(null);
let runtimeEnvironment: Environment = $derived.by(() => {
const refreshed = refreshedEnvironment;
@@ -285,9 +291,10 @@
// Build current settings object from environment and settings data
const currentSettings = $derived({
- name: environment.name,
- enabled: environment.enabled,
- apiUrl: environment.apiUrl,
+ name: loadedEnvironment.name,
+ enabled: loadedEnvironment.enabled,
+ apiUrl: loadedEnvironment.apiUrl,
+ accessToken: '',
pollingEnabled: settings?.pollingEnabled ?? false,
imageEventWatcherEnabled: settings?.imageEventWatcherEnabled ?? false,
autoUpdate: settings?.autoUpdate ?? false,
@@ -349,6 +356,8 @@
// Custom save handler for environment-specific settings
async function saveEnvironmentSettings(formData: EnvironmentFormValues) {
const environmentId = environment.id;
+ const submittedInputs = formInputs;
+ const apiUrlChanged = formData.apiUrl !== environment.apiUrl;
const featureChanged =
formData.featureVulnerabilityManagementEnabled !== currentSettings.featureVulnerabilityManagementEnabled;
if (
@@ -357,22 +366,26 @@
) {
throw new Error(m.features_unavailable());
}
- if (
- formData.name !== environment.name ||
- formData.enabled !== environment.enabled ||
- formData.apiUrl !== environment.apiUrl
- ) {
- await environmentManagementService.update(environmentId, {
- name: formData.name,
- enabled: formData.enabled,
- apiUrl: formData.apiUrl
+ if (formData.name !== environment.name || formData.enabled !== environment.enabled || apiUrlChanged) {
+ const update = environmentUpdateSchema.parse({
+ ...formData,
+ accessToken: directRemoteUrlChanged ? formData.accessToken : undefined
});
+ const result = await tryCatch(environmentManagementService.update(environmentId, update));
+ if (result.error) {
+ throw new Error(result.error.message);
+ }
+ submittedInputs.accessToken.value = '';
+ formData.accessToken = '';
+ if (environment.id === environmentId) {
+ environment = result.data;
+ }
}
const parsedCurrentSettings = formSchema.safeParse(currentSettings);
const savedFormValues = parsedCurrentSettings.success ? parsedCurrentSettings.data : currentSettings;
const otherSettingsChanged = (Object.keys(formData) as (keyof EnvironmentFormValues)[]).some(
(key) =>
- !['name', 'enabled', 'apiUrl', 'featureVulnerabilityManagementEnabled'].includes(key) &&
+ !['name', 'enabled', 'apiUrl', 'accessToken', 'featureVulnerabilityManagementEnabled'].includes(key) &&
formData[key] !== savedFormValues[key]
);
let updates: Partial<Settings> = {};
@@ -461,17 +474,35 @@
}
}
+ function clearAccessToken(): void {
+ formInputs.accessToken.value = '';
+ }
+
let { formInputs, settingsForm, resetForm, onSubmit } = $derived(
createSettingsForm({
schema: formSchema,
currentSettings,
- getCurrentSettings: () => currentSettings,
+ getCurrentSettings: () => ({
+ ...currentSettings,
+ name: environment.name,
+ enabled: environment.enabled,
+ apiUrl: environment.apiUrl
+ }),
onSave: saveEnvironmentSettings,
successMessage: m.common_update_success({ resource: m.resource_environment_cap() }),
errorMessage: m.common_update_failed({ resource: m.resource_environment() }),
onReset: () => toast.info(m.changes_reset())
})
);
+ let directRemoteUrlChanged = $derived(
+ environment.id !== '0' && !environment.isEdge && formInputs.apiUrl.value !== environment.apiUrl
+ );
+
+ beforeNavigate((navigation) => {
+ if (navigation.willUnload || (navigation.to && navigation.to.url.pathname !== navigation.from?.url.pathname)) {
+ clearAccessToken();
+ }
+ });
const shellOptions = [
{ value: '/bin/sh', label: '/bin/sh', description: m.docker_shell_sh_description() },
@@ -693,6 +724,7 @@
id="api-url"
type="url"
bind:value={formInputs.apiUrl.value}
+ oninput={clearAccessToken}
class="h-7 w-full max-w-md font-mono text-xs {formInputs.apiUrl.error ? 'border-destructive' : ''}"
placeholder={m.environments_api_url_placeholder()}
autofocus
@@ -703,6 +735,7 @@
}
if (e.key === 'Escape') {
formInputs.apiUrl.value = environment.apiUrl;
+ clearAccessToken();
isEditingApiUrl = false;
}
}}
@@ -732,6 +765,19 @@
{#if formInputs.apiUrl.error}
<p class="mt-1 text-xs text-destructive">{formInputs.apiUrl.error}</p>
{/if}
+ {#if directRemoteUrlChanged}
+ <div class="mt-3 max-w-md">
+ <TextInputWithLabel
+ id="agent-access-token-for-url"
+ type="password"
+ autocomplete="off"
+ label={m.environments_access_token_for_url_label()}
+ description={m.environments_access_token_for_url_help()}
+ bind:value={formInputs.accessToken.value}
+ disabled={settingsForm.isLoading}
+ />
+ </div>
+ {/if}
</div>
</div>
diff --git a/frontend/src/routes/(app)/environments/[id]/components/environment-form-schema.ts b/frontend/src/routes/(app)/environments/[id]/components/environment-form-schema.ts
index 4e42e5009..1ef3f832d 100644
--- a/frontend/src/routes/(app)/environments/[id]/components/environment-form-schema.ts
+++ b/frontend/src/routes/(app)/environments/[id]/components/environment-form-schema.ts
@@ -1,11 +1,20 @@
import { z } from 'zod/v4';
import { m } from '#lib/paraglide/messages.js';
-export const environmentFormSchema = z
- .object({
- name: z.string().min(1),
- enabled: z.boolean(),
- apiUrl: z.string(),
+export const environmentUpdateSchema = z.object({
+ name: z.string().min(1),
+ enabled: z.boolean(),
+ apiUrl: z.string(),
+ accessToken: z
+ .string()
+ .trim()
+ .optional()
+ .transform((value) => value || undefined)
+});
+
+export const environmentFormSchema = environmentUpdateSchema
+ .extend({
+ accessToken: z.string(),
pollingEnabled: z.boolean(),
imageEventWatcherEnabled: z.boolean(),
autoUpdate: z.boolean(),
diff --git a/tests/setup/compose-postgres.yaml b/tests/setup/compose-postgres.yaml
index bd19141ac..8d3c2af19 100644
--- a/tests/setup/compose-postgres.yaml
+++ b/tests/setup/compose-postgres.yaml
@@ -4,7 +4,11 @@ services:
# A directory created under the data dir is served as a bucket, so backups
# have somewhere to write without a separate provisioning container.
entrypoint:
- ['sh', '-c', 'mkdir -p /data/arcane-backups && exec minio server /data --address :9000']
+ [
+ 'sh',
+ '-c',
+ 'mkdir -p /data/arcane-backups && exec minio server /data --address :9000 --console-address :9001'
+ ]
environment:
- MINIO_ROOT_USER=arcane-test
- MINIO_ROOT_PASSWORD=arcane-test-secret
diff --git a/tests/setup/compose-proxy.yaml b/tests/setup/compose-proxy.yaml
index d58dacf9c..4e5c060ef 100644
--- a/tests/setup/compose-proxy.yaml
+++ b/tests/setup/compose-proxy.yaml
@@ -4,7 +4,11 @@ services:
# A directory created under the data dir is served as a bucket, so backups
# have somewhere to write without a separate provisioning container.
entrypoint:
- ['sh', '-c', 'mkdir -p /data/arcane-backups && exec minio server /data --address :9000']
+ [
+ 'sh',
+ '-c',
+ 'mkdir -p /data/arcane-backups && exec minio server /data --address :9000 --console-address :9001'
+ ]
environment:
- MINIO_ROOT_USER=arcane-test
- MINIO_ROOT_PASSWORD=arcane-test-secret
diff --git a/tests/setup/compose.yaml b/tests/setup/compose.yaml
index 7aaf357f6..bfc73f278 100644
--- a/tests/setup/compose.yaml
+++ b/tests/setup/compose.yaml
@@ -4,7 +4,11 @@ services:
# A directory created under the data dir is served as a bucket, so backups
# have somewhere to write without a separate provisioning container.
entrypoint:
- ['sh', '-c', 'mkdir -p /data/arcane-backups && exec minio server /data --address :9000']
+ [
+ 'sh',
+ '-c',
+ 'mkdir -p /data/arcane-backups && exec minio server /data --address :9000 --console-address :9001'
+ ]
environment:
- MINIO_ROOT_USER=arcane-test
- MINIO_ROOT_PASSWORD=arcane-test-secret
diff --git a/tests/spec/environment-settings.spec.ts b/tests/spec/environment-settings.spec.ts
index feb23adef..64d7e2aa1 100644
--- a/tests/spec/environment-settings.spec.ts
+++ b/tests/spec/environment-settings.spec.ts
@@ -47,17 +47,18 @@ async function createDirectEnvironmentViaUI(
);
await page.getByRole('button', { name: 'Generate Agent Configuration', exact: true }).click();
const createResponse = await createResponsePromise;
- expect(createResponse.ok(), await createResponse.text()).toBeTruthy();
- const created: { data: { id: string } } = await createResponse.json();
+ expect(createResponse.ok(), 'Create direct environment').toBeTruthy();
+ const created: { data: { id: string; apiKey?: string } } = await createResponse.json();
environmentIds.add(created.data.id);
expect(created.data.id).toBeTruthy();
+ if (!created.data.apiKey) throw new Error('New agent environment did not return an API key');
await expect(
page.getByRole('heading', { name: 'Environment Created Successfully', exact: true })
).toBeVisible();
await page.getByRole('button', { name: 'Done', exact: true }).click();
await expect(page.getByRole('button', { name: environmentName, exact: true })).toBeVisible();
- return created.data.id;
+ return { id: created.data.id, apiKey: created.data.apiKey };
}
async function openLocalEnvironment(page: Page) {
@@ -79,6 +80,7 @@ async function saveAndWaitForPut(page: Page, expectedPath: string) {
const response = await responsePromise;
expect(response.ok(), `Expected successful PUT to ${expectedPath}`).toBeTruthy();
await expect(saveButton).toBeDisabled({ timeout: 10000 });
+ return response.request();
}
async function selectSettingOption(page: Page, trigger: Locator, optionText: string) {
@@ -191,19 +193,104 @@ test.describe('Environment Settings UI', () => {
test.setTimeout(120_000); // 120 seconds timeout for this lengthy UI workflow
const envName = `settings-ui-${Date.now().toString().slice(-5)}`;
const updatedName = `${envName}-updated`;
- let environmentId = '';
const environmentIds = new Set<string>();
try {
- environmentId = await createDirectEnvironmentViaUI(page, envName, environmentIds);
+ const { id: environmentId, apiKey } = await createDirectEnvironmentViaUI(
+ page,
+ envName,
+ environmentIds
+ );
+ const environmentPath = `/api/environments/${environmentId}`;
await page.getByRole('button', { name: envName, exact: true }).click();
await expect(page).toHaveURL(/\/environments\/[^/?]+\?tab=[a-z]+$/);
+ const apiUrlButton = page.getByTitle('API URL', { exact: true });
+ const originalApiUrl = (await apiUrlButton.textContent())!.trim();
+ const updatedApiUrl = originalApiUrl.replace(':3552', ':3553');
+ expect(updatedApiUrl).not.toBe(originalApiUrl);
+
await renameEnvironmentInHeader(page, updatedName);
- await saveAndWaitForPut(page, `/api/environments/${environmentId}`);
+ const nameRequest = await saveAndWaitForPut(page, environmentPath);
+ expect(nameRequest.postDataJSON()).not.toHaveProperty('accessToken');
await page.reload();
await expect(environmentTitleButton(page)).toHaveText(updatedName);
+
+ await apiUrlButton.click();
+ await page.locator('#api-url').fill(updatedApiUrl);
+ await page.locator('#api-url').press('Tab');
+ const tokenInput = page.getByLabel('Agent access token', { exact: true });
+ await expect(tokenInput).toBeVisible();
+ await expect(tokenInput).toHaveAttribute('type', 'password');
+ await expect(tokenInput).toHaveValue('');
+
+ const rejectedResponsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'PUT' &&
+ new URL(response.url()).pathname === environmentPath
+ );
+ await page.getByRole('button', { name: 'Save', exact: true }).first().click();
+ const rejectedResponse = await rejectedResponsePromise;
+ expect(rejectedResponse.status()).toBe(400);
+ expect(rejectedResponse.request().postDataJSON()).not.toHaveProperty('accessToken');
+ await expect(
+ page.getByText('Changing environment API URL requires re-entering the accessToken')
+ ).toBeVisible();
+ const afterRejection = await page.request.get(environmentPath);
+ expect(afterRejection.ok()).toBe(true);
+ expect(((await afterRejection.json()) as { data: { apiUrl: string } }).data.apiUrl).toBe(
+ originalApiUrl
+ );
+
+ await tokenInput.fill(apiKey);
+ await apiUrlButton.click();
+ await page.locator('#api-url').fill(`${updatedApiUrl}/changed`);
+ await page.locator('#api-url').press('Tab');
+ await expect(tokenInput).toHaveValue('');
+ await apiUrlButton.click();
+ await page.locator('#api-url').fill(updatedApiUrl);
+ await page.locator('#api-url').press('Tab');
+ await tokenInput.fill(apiKey);
+ await page.route(`**${environmentPath}`, async (route) => {
+ if (route.request().method() !== 'PUT') return route.continue();
+ await route.fulfill({
+ status: 503,
+ contentType: 'application/problem+json',
+ body: JSON.stringify({ detail: 'Temporary update failure' })
+ });
+ });
+ const failedResponsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'PUT' &&
+ new URL(response.url()).pathname === environmentPath
+ );
+ await page.getByRole('button', { name: 'Save', exact: true }).first().click();
+ expect((await failedResponsePromise).status()).toBe(503);
+ await expect(page.getByText('Temporary update failure')).toBeVisible();
+ expect((await tokenInput.inputValue()) === apiKey).toBe(true);
+ await page.unroute(`**${environmentPath}`);
+
+ const updateRequest = await saveAndWaitForPut(page, environmentPath);
+ const updatePayload = updateRequest.postDataJSON() as Record<string, unknown>;
+ expect(updatePayload.apiUrl).toBe(updatedApiUrl);
+ expect(updatePayload.accessToken === apiKey).toBe(true);
+ await expect(tokenInput).toBeHidden();
+ await apiUrlButton.click();
+ await page.locator('#api-url').fill(`${updatedApiUrl}/another`);
+ await page.locator('#api-url').press('Tab');
+ await expect(tokenInput).toHaveValue('');
+ await apiUrlButton.click();
+ await page.locator('#api-url').press('Escape');
+ await expect(apiUrlButton).toHaveText(updatedApiUrl);
+ await expect(tokenInput).toBeHidden();
+
+ await page.reload();
+ await expect(apiUrlButton).toHaveText(updatedApiUrl);
+ await expect(tokenInput).toBeHidden();
+ await renameEnvironmentInHeader(page, `${updatedName}-again`);
+ const secondNameRequest = await saveAndWaitForPut(page, environmentPath);
+ expect(secondNameRequest.postDataJSON()).not.toHaveProperty('accessToken');
} finally {
for (const id of environmentIds) await removeApiResource(page, `/api/environments/${id}`);
}
@@ -211,6 +298,7 @@ test.describe('Environment Settings UI', () => {
test('should update and save the base server URL in Docker settings', async ({ page }) => {
await openLocalEnvironment(page);
+ await expect(page.getByLabel('Agent access token', { exact: true })).toBeHidden();
await page.getByRole('tab', { name: 'Docker Settings', exact: true }).click();
const baseServerUrlInput = page.locator('#base-server-url');
@@ -224,7 +312,11 @@ test.describe('Environment Settings UI', () => {
try {
await baseServerUrlInput.fill(updatedBaseServerUrl);
await expect(baseServerUrlInput).toHaveValue(updatedBaseServerUrl);
- await saveAndWaitForPut(page, `/api/environments/${LOCAL_ENV_ID}/settings`);
+ const settingsRequest = await saveAndWaitForPut(
+ page,
+ `/api/environments/${LOCAL_ENV_ID}/settings`
+ );
+ expect(settingsRequest.postDataJSON()).not.toHaveProperty('accessToken');
await page.reload();
await page.getByRole('tab', { name: 'Docker Settings', exact: true }).click();
@@ -297,21 +389,53 @@ test.describe('Environment Settings UI', () => {
});
test('should reset unsaved environment detail changes', async ({ page }) => {
- await openLocalEnvironment(page);
-
- const titleButton = environmentTitleButton(page);
- const originalName = (await titleButton.textContent())!.trim();
- await renameEnvironmentInHeader(page, `${originalName}-pending`);
-
- const saveButton = page.getByRole('button', { name: 'Save', exact: true }).first();
- const resetButton = page.getByRole('button', { name: 'Reset', exact: true }).first();
-
- await expect(saveButton).toBeEnabled();
- await expect(resetButton).toBeVisible();
- await resetButton.click();
+ const envName = `settings-reset-${Date.now().toString().slice(-5)}`;
+ const environmentIds = new Set<string>();
+ try {
+ const { id: environmentId, apiKey } = await createDirectEnvironmentViaUI(
+ page,
+ envName,
+ environmentIds
+ );
+ await openEnvironment(page, environmentId);
+ const titleButton = environmentTitleButton(page);
+ const apiUrlButton = page.getByTitle('API URL', { exact: true });
+ const originalApiUrl = (await apiUrlButton.textContent())!.trim();
+ await renameEnvironmentInHeader(page, `${envName}-pending`);
+ await apiUrlButton.click();
+ await page.locator('#api-url').fill(originalApiUrl.replace(':3552', ':3553'));
+ await page.locator('#api-url').press('Tab');
+ const tokenInput = page.getByLabel('Agent access token', { exact: true });
+ await tokenInput.fill(apiKey);
- await expect(titleButton).toHaveText(originalName);
- await expect(saveButton).toBeDisabled();
+ const saveButton = page.getByRole('button', { name: 'Save', exact: true }).first();
+ const resetButton = page.getByRole('button', { name: 'Reset', exact: true }).first();
+ await expect(saveButton).toBeEnabled();
+ await expect(resetButton).toBeVisible();
+ await resetButton.click();
+ await expect(titleButton).toHaveText(envName);
+ await expect(apiUrlButton).toHaveText(originalApiUrl);
+ await expect(tokenInput).toBeHidden();
+ await expect(saveButton).toBeDisabled();
+
+ await apiUrlButton.click();
+ await page.locator('#api-url').fill(originalApiUrl.replace(':3552', ':3553'));
+ await page.locator('#api-url').press('Tab');
+ await expect(tokenInput).toHaveValue('');
+ await tokenInput.fill(apiKey);
+ await page.getByRole('button', { name: 'Back to Environments', exact: true }).click();
+ await expect(page).toHaveURL(/\/environments$/);
+ await expect(page.getByRole('heading', { name: 'Environments', exact: true })).toBeVisible();
+ await page.getByRole('button', { name: envName, exact: true }).click();
+ await expect(page).toHaveURL(new RegExp(`/environments/${environmentId}(?:\\?|$)`));
+ await expect(environmentTitleButton(page)).toHaveText(envName);
+ await apiUrlButton.click();
+ await page.locator('#api-url').fill(originalApiUrl.replace(':3552', ':3553'));
+ await page.locator('#api-url').press('Tab');
+ await expect(tokenInput).toHaveValue('');
+ } finally {
+ for (const id of environmentIds) await removeApiResource(page, `/api/environments/${id}`);
+ }
});
test('should update and save the default deploy pull policy in Docker settings', async ({