Repository navigation
fix(ec2): keep AWS-managed instance tags read-only #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fredpena
merged 5 commits into
floci-io:main
from
AndreKurait:fix/ec2-protected-tag-editor
Oct 14, 2026
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0ff48b1
fix(ec2): keep AWS-managed instance tags read-only
AndreKurait 4424654
fix(ec2): use the protected tag editor in the console
AndreKurait de81d25
fix(ec2): preserve unsaved tag edits during refresh
AndreKurait 6e1d583
Merge remote-tracking branch 'origin/main' into fix/ec2-protected-tag…
AndreKurait 2f932ae
fix(ec2): finish tag refresh before accepting another edit
AndreKurait File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
| import { render, screen, waitFor } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { expect, test, vi } from "vitest"; | ||
| import { ComputePanel } from "./ComputePanel"; | ||
| import { describeEc2Instance, updateEc2InstanceTags } from "@/api/aws/ec2.api"; | ||
|
|
||
| vi.mock("@/api/aws/ec2.api", async (importOriginal) => ({ | ||
| ...await importOriginal<typeof import("@/api/aws/ec2.api")>(), | ||
| describeEc2Instance: vi.fn(), | ||
| updateEc2InstanceTags: vi.fn(), | ||
| })); | ||
|
|
||
| test("the console protects system tags and refreshes after saving an ordinary tag", async () => { | ||
| vi.mocked(describeEc2Instance).mockResolvedValue({ | ||
| instanceId: "i-test", name: "test", state: "running", instanceType: "t3.nano", | ||
| tags: [{ key: "aws:autoscaling:groupName", value: "group" }, { key: "Name", value: "before" }], | ||
| securityGroups: [], | ||
| }); | ||
| vi.mocked(updateEc2InstanceTags).mockResolvedValue(undefined); | ||
| const client = new QueryClient({ defaultOptions: { queries: { retry: false } } }); | ||
| const user = userEvent.setup(); | ||
| render(<QueryClientProvider client={client}> | ||
| <ComputePanel cloud="aws" runtimeReachable resource={{ | ||
| id: "i-test", name: "test", cloud: "aws", service: "compute", type: "instance", | ||
| region: "us-east-1", createdAt: null, metadata: {}, | ||
| }} /> | ||
| </QueryClientProvider>); | ||
| await user.click(await screen.findByRole("button", { name: "Tags" })); | ||
| expect(screen.getByDisplayValue("aws:autoscaling:groupName")).toHaveAttribute("readonly"); | ||
| expect(screen.getByDisplayValue("group")).toHaveAttribute("readonly"); | ||
| expect(screen.getAllByRole("button", { name: "Remove" })).toHaveLength(1); | ||
| await user.clear(screen.getByDisplayValue("before")); | ||
| await user.type(screen.getByPlaceholderText("Value"), "after"); | ||
| await user.click(screen.getByRole("button", { name: "Save tags" })); | ||
| await waitFor(() => expect(updateEc2InstanceTags).toHaveBeenCalledWith( | ||
| "i-test", [{ key: "Name", value: "after" }], [], | ||
| )); | ||
| await waitFor(() => expect(describeEc2Instance).toHaveBeenCalledTimes(2)); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { beforeEach, expect, test, vi } from "vitest"; | ||
| import { TagEditor } from "./TagEditor"; | ||
|
|
||
| const { mutate } = vi.hoisted(() => ({ mutate: vi.fn() })); | ||
| vi.mock("@/api/aws/ec2.mutations", () => ({ | ||
| useUpdateEc2InstanceTagsMutation: () => ({ mutate, isPending: false }), | ||
| })); | ||
|
|
||
| beforeEach(() => mutate.mockClear()); | ||
|
|
||
| test("shows AWS-owned tags read-only and saves only user tag changes", async () => { | ||
| render(<TagEditor instanceId="i-test" initialTags={[ | ||
| { key: "aws:autoscaling:groupName", value: "group" }, | ||
| { key: "AWS:other", value: "managed" }, | ||
| { key: "Name", value: "old" }, | ||
| { key: "remove-me", value: "old" }, | ||
| ]} />); | ||
| const user = userEvent.setup(); | ||
| expect(screen.getByDisplayValue("aws:autoscaling:groupName")).toHaveAttribute("readonly"); | ||
| expect(screen.getByDisplayValue("group")).toHaveAttribute("readonly"); | ||
| expect(screen.getByDisplayValue("AWS:other")).toHaveAttribute("readonly"); | ||
| expect(screen.getAllByRole("button", { name: "Remove" })).toHaveLength(2); | ||
| await user.clear(screen.getAllByPlaceholderText("Value")[0]); | ||
| await user.type(screen.getAllByPlaceholderText("Value")[0], "updated"); | ||
| await user.click(screen.getAllByRole("button", { name: "Remove" })[1]); | ||
| await user.click(screen.getByRole("button", { name: "Save tags" })); | ||
| expect(mutate).toHaveBeenCalledWith({ | ||
| instanceId: "i-test", toAdd: [{ key: "Name", value: "updated" }], toRemove: ["remove-me"], | ||
| }, expect.anything()); | ||
| }); | ||
|
|
||
| test.each(["aws:custom", "AWS:custom", "aWs:custom"])("rejects a new reserved key %s without locking its input", async (key) => { | ||
| render(<TagEditor instanceId="i-test" initialTags={[]} />); | ||
| const user = userEvent.setup(); | ||
| await user.click(screen.getByRole("button", { name: "Add tag" })); | ||
| await user.type(screen.getByPlaceholderText("Key"), key); | ||
| await user.click(screen.getByRole("button", { name: "Save tags" })); | ||
| expect(screen.getByText("Tag keys starting with 'aws:' are reserved for AWS.")).toBeVisible(); | ||
| expect(mutate).not.toHaveBeenCalled(); | ||
| await user.clear(screen.getByPlaceholderText("Key")); | ||
| await user.type(screen.getByPlaceholderText("Key"), "Name"); | ||
| await user.click(screen.getByRole("button", { name: "Save tags" })); | ||
| expect(mutate).toHaveBeenCalledWith({ | ||
| instanceId: "i-test", toAdd: [{ key: "Name", value: "" }], toRemove: [], | ||
| }, expect.anything()); | ||
| }); | ||
| test("keeps unsaved edits on refresh and does not delete externally added tags", async () => { | ||
| const { rerender } = render(<TagEditor instanceId="i-test" initialTags={[ | ||
| { key: "aws:autoscaling:groupName", value: "group-a" }, | ||
| { key: "Name", value: "before" }, | ||
| ]} />); | ||
| const user = userEvent.setup(); | ||
| await user.clear(screen.getByDisplayValue("before")); | ||
| await user.type(screen.getByPlaceholderText("Value"), "draft"); | ||
| rerender(<TagEditor instanceId="i-test" initialTags={[ | ||
| { key: "aws:autoscaling:groupName", value: "group-b" }, | ||
| { key: "Name", value: "external" }, | ||
| { key: "External", value: "keep" }, | ||
| ]} />); | ||
| expect(screen.getByDisplayValue("draft")).toBeVisible(); | ||
| expect(screen.getByDisplayValue("group-b")).toHaveAttribute("readonly"); | ||
| await user.click(screen.getByRole("button", { name: "Save tags" })); | ||
| expect(mutate).toHaveBeenCalledWith({ | ||
| instanceId: "i-test", toAdd: [{ key: "Name", value: "draft" }], toRemove: [], | ||
| }, expect.anything()); | ||
| }); | ||
|
|
||
| test("refreshes pristine rows without starting a draft", () => { | ||
| const { rerender } = render(<TagEditor instanceId="i-test" initialTags={[{ key: "Name", value: "before" }]} />); | ||
| rerender(<TagEditor instanceId="i-test" initialTags={[{ key: "Name", value: "after" }]} />); | ||
| expect(screen.getByDisplayValue("after")).toBeVisible(); | ||
| expect(screen.queryByDisplayValue("before")).not.toBeInTheDocument(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.