towerops/test/towerops_web/live/agent_live/edit_test.exs
Graham McIntire aa9ed52bff
feat: add critical network switch sensor support (HP Comware, Dell PowerConnect, Dell SONiC)
Implemented top 3 critical network switch sensor gaps identified in Phase 3 analysis.
Restores fundamental temperature monitoring for common enterprise switch platforms.

Files Changed:
- priv/profiles/os_discovery/comware.yaml (enhanced)
  Added HP Comware chassis temperature monitoring via HH3C-ENTITY-EXT-MIB
  OID: 1.3.6.1.4.1.25506.2.6.1.1.1.1.12 (hh3cEntityExtTemperature)
  Uses entPhysicalName for sensor descriptions
  Gap: CRITICAL (broke fundamental monitoring) → RESOLVED
  Parity: 40% → 60%

- priv/profiles/os_discovery/powerconnect.yaml (enhanced)
  Added Dell PowerConnect/DNOS CPU temperature monitoring
  OID: 1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.8.1.5
  MIB: FASTPATH-BOXSERVICES-PRIVATE-MIB
  Gap: CRITICAL (no sensors) → RESOLVED
  Parity: 0% → 80%

- priv/profiles/os_discovery/dell-sonic.yaml (new)
  Created comprehensive Dell SONiC sensor profile
  MIB: NETGEAR-BOXSERVICES-PRIVATE-MIB (Quanta-based)
  Sensors:
    - Temperature: boxServicesTempSensorState (OID .1.3.6.1.4.1.4413.1.1.43.1.8.1.4)
    - Fan Speed: boxServicesFanSpeed (OID .1.3.6.1.4.1.4413.1.1.43.1.6.1.4)
    - PSU State: boxServicesPowSupplyItemState (OID .1.3.6.1.4.1.4413.1.1.43.1.7.1.3)
      States: other, notpresent, operational, failed, powering, nopower,
              notpowering, incompatible
  Gap: CRITICAL (OS detected, no sensors) → RESOLVED
  Parity: 0% → 95%

- test/towerops_web/plugs/brute_force_protection_test.exs (fixed)
  Fixed Credo warning: replaced length/1 with empty list comparison

- CHANGELOG.txt (updated)
  Documented Phase 3 analysis completion and critical fix implementation

Impact:
- HP Comware: Enables overheating alerts (fundamental monitoring restored)
- Dell PowerConnect: First sensor support for common access switches
- Dell SONiC: Complete hardware monitoring for modern data center platform

Business Value:
- Resolves production blockers for customers with HP Comware switches
- Adds support for very common Dell enterprise access switches
- Enables monitoring for Dell's modern SONiC-based data center switches

Next Steps: Remaining Tier 1 switches (Dell Force10 FTOS), then Tier 2
(optical transceiver monitoring for ProCurve/Comware).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-11 17:36:45 -06:00

168 lines
5.1 KiB
Elixir

defmodule ToweropsWeb.AgentLive.EditTest do
use ToweropsWeb.ConnCase
import Phoenix.LiveViewTest
alias Towerops.AgentsFixtures
setup %{conn: conn} do
user = Towerops.AccountsFixtures.user_fixture()
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Test Org"}, user.id)
conn =
conn
|> log_in_user(user)
|> put_session(:current_organization_id, organization.id)
%{conn: conn, user: user, organization: organization}
end
defp create_agent(organization_id, name \\ nil) do
{:ok, agent_token, _raw_token} = AgentsFixtures.agent_token_fixture(organization_id, name)
agent_token
end
describe "mount and display" do
test "renders edit form with agent name", %{conn: conn, organization: org} do
agent = create_agent(org.id, "Original Agent Name")
{:ok, _view, html} = live(conn, ~p"/agents/#{agent.id}/edit")
assert html =~ "Edit Agent"
assert html =~ "Original Agent Name"
assert html =~ "Agent Name"
assert html =~ "Save Changes"
assert html =~ "Cancel"
end
test "displays allow remote debug checkbox", %{conn: conn, organization: org} do
agent = create_agent(org.id)
{:ok, _view, html} = live(conn, ~p"/agents/#{agent.id}/edit")
assert html =~ "Allow Remote Debugging"
end
test "displays back to agent link", %{conn: conn, organization: org} do
agent = create_agent(org.id)
{:ok, _view, html} = live(conn, ~p"/agents/#{agent.id}/edit")
assert html =~ "Back to agent"
assert html =~ ~p"/agents/#{agent.id}"
end
test "sets page title to Edit plus agent name", %{conn: conn, organization: org} do
agent = create_agent(org.id, "My Agent")
{:ok, _view, html} = live(conn, ~p"/agents/#{agent.id}/edit")
assert html =~ "Edit My Agent"
end
end
describe "form validation" do
test "validates name changes in real time", %{conn: conn, organization: org} do
agent = create_agent(org.id, "Original Name")
{:ok, view, _html} = live(conn, ~p"/agents/#{agent.id}/edit")
# Submit empty name to trigger validation error
html =
view
|> form("#edit-agent-form", agent_token: %{name: ""})
|> render_change()
assert html =~ "can&#39;t be blank" || html =~ "can't be blank"
end
test "validates with valid name", %{conn: conn, organization: org} do
agent = create_agent(org.id, "Original Name")
{:ok, view, _html} = live(conn, ~p"/agents/#{agent.id}/edit")
html =
view
|> form("#edit-agent-form", agent_token: %{name: "Updated Agent Name"})
|> render_change()
refute html =~ "can&#39;t be blank"
refute html =~ "can't be blank"
end
end
describe "form submission" do
test "saves changes and redirects to show page", %{conn: conn, organization: org} do
agent = create_agent(org.id, "Original Name")
{:ok, view, _html} = live(conn, ~p"/agents/#{agent.id}/edit")
view
|> form("#edit-agent-form", agent_token: %{name: "Updated Agent Name"})
|> render_submit()
flash = assert_redirect(view, ~p"/agents/#{agent.id}")
assert flash["info"] =~ "Agent updated successfully"
end
test "shows error when saving with blank name", %{conn: conn, organization: org} do
agent = create_agent(org.id, "Original Name")
{:ok, view, _html} = live(conn, ~p"/agents/#{agent.id}/edit")
html =
view
|> form("#edit-agent-form", agent_token: %{name: ""})
|> render_submit()
assert html =~ "can&#39;t be blank" || html =~ "can't be blank"
end
end
describe "authentication" do
test "redirects to login when not authenticated" do
conn = build_conn()
assert {:error, {:redirect, %{to: to}}} =
live(conn, ~p"/agents/#{Ecto.UUID.generate()}/edit")
assert to =~ "/users/log-in"
end
end
describe "authorization" do
test "raises when editing agent from another organization", %{conn: conn} do
other_user = Towerops.AccountsFixtures.user_fixture()
{:ok, other_org} = Towerops.Organizations.create_organization(%{name: "Other Org"}, other_user.id)
other_agent = create_agent(other_org.id, "Other Org Agent")
assert_raise Ecto.NoResultsError, fn ->
live(conn, ~p"/agents/#{other_agent.id}/edit")
end
end
test "superuser can edit agent from any organization" do
superuser = Towerops.AccountsFixtures.user_fixture()
superuser
|> Ecto.Changeset.change(%{is_superuser: true})
|> Towerops.Repo.update!()
{:ok, super_org} = Towerops.Organizations.create_organization(%{name: "Super Org"}, superuser.id)
other_user = Towerops.AccountsFixtures.user_fixture()
{:ok, other_org} = Towerops.Organizations.create_organization(%{name: "Other Org"}, other_user.id)
other_agent = create_agent(other_org.id, "Cross-Org Agent")
super_conn =
build_conn()
|> log_in_user(superuser)
|> put_session(:current_organization_id, super_org.id)
{:ok, _view, html} = live(super_conn, ~p"/agents/#{other_agent.id}/edit")
assert html =~ "Cross-Org Agent"
end
end
end