Commit graph

58 commits

Author SHA1 Message Date
a2d96f8e6e
Implement hierarchical agent assignment for SNMP polling
Add three-level agent assignment hierarchy (Equipment > Site > Organization)
allowing flexible agent deployment strategies. Agents now receive only equipment
assigned to them through direct assignment or inheritance from site/organization
defaults.

Key changes:
- Add agent_token_id to Sites table with migration
- Implement get_effective_agent_token/1 for hierarchical resolution
- Add list_agent_polling_targets/1 to return polling targets per agent
- Update API config endpoint to use hierarchical polling targets
- Add agent assignment UI to equipment, site, and organization forms
- Show agent source (direct/site/org/none) in equipment form
- Add equipment count column to agent list
- Update terminology from "poll from server" to "cloud polling"

Tests:
- Add 8 comprehensive tests for list_agent_polling_targets/1
- Add end-to-end test for hierarchical config endpoint
- All 775 tests passing
2026-01-14 08:38:50 -06:00
b8bd952681
agent token changes 2026-01-13 13:43:43 -06:00
f9b575816a
Fix database ownership issues in agent auth tests
- Update AgentAuth plug to use synchronous heartbeat updates in test env
- Refactor async heartbeat logic to reduce nesting (Credo)
- Remove Process.sleep from tests (no longer needed with sync updates)

This fixes 'owner exited' database errors in the test suite by avoiding
async Task spawns during tests, which caused DB connection ownership
conflicts with Ecto's sandbox mode.
2026-01-13 13:16:54 -06:00
3eb95b5f90
Streamline login flow and fix test failures
Login flow improvements:
- Remove "Welcome back!" flash message on successful login
- Auto-login users clicking magic links without confirmation prompt
- Always use "remember me" for magic link logins
- Fix Accounts.login_user_by_magic_link/1 to handle invalid token format

Test fixes:
- Add @tag :integration to Ping tests (require actual system ping)
- Add halt() calls to UserAuth.start_impersonation error paths

Users now go directly to their intended destination after clicking a
magic link, with no interruption for "log in and stay logged in" choice.
2026-01-13 13:08:24 -06:00
11bc5dec4a
no post login page 2026-01-13 12:27:17 -06:00
d16f105f15
more tests 2026-01-13 09:18:25 -06:00
fc1b6ea026
Add comprehensive tests for EquipmentLive.Show
- Test equipment information display
- Test overview tab rendering
- Test metrics display with monitoring checks
- Test empty state handling
- Test periodic data refresh
- Test authentication requirement
- Test event handling (equipment_status_changed, discovery_completed)
- Test tab switching functionality
2026-01-13 09:13:40 -06:00
167f853a63
Add comprehensive tests for Sites.Site schema
- Test valid changesets with required and all fields
- Test validation for name, description, location lengths
- Test parent site relationships and circular reference validation
- Test all constraint validations
2026-01-13 09:05:02 -06:00
7a33fbff66
Add tests for OrganizationsFixtures
- Test unique organization name generation
- Test valid organization attributes
- Test organization creation with defaults and custom attributes
- Test membership creation for organization owner
2026-01-13 08:59:40 -06:00
2c35ad457c
Add comprehensive tests for AccountsFixtures
- Test all fixture generation functions
- Test user creation (confirmed and unconfirmed)
- Test scope fixtures
- Test password setting
- Test token generation and manipulation
- Test credential fixtures
2026-01-13 08:57:49 -06:00
d58f6b2d3a
Add tests for Monitoring.Ping and OrgLive.New
- Add comprehensive tests for Towerops.Monitoring.Ping module
- Test successful pings, timeouts, error handling, and OS detection
- Add tests for ToweropsWeb.OrgLive.New LiveView
- Test form validation, organization creation, and authentication
2026-01-13 08:54:49 -06:00
b35071d106
Fix unused import warning in agent_live_test.exs
Change from fully-qualified Ecto.Query.from() calls to using
the imported from() macro directly to eliminate unused import
warning.
2026-01-13 08:48:42 -06:00
0689fec38c
Add AgentsFixtures tests
Added 4 tests covering all fixture functions:
- unique_agent_name/0 generation
- agent_token_fixture/2 with default and custom names
- agent_assignment_fixture/2 creation

Coverage increased from 40% to 100%.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 08:42:15 -06:00
19953ae289
Add AgentLive.Index edge case tests
Added 4 tests covering previously untested scenarios:
- Agent with warning status (2-5 minutes offline)
- Agent with offline status (>5 minutes offline)
- Last seen time formatting (hours and days)

Coverage increased from 80% to near 100%.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 08:41:07 -06:00
00ebe0c5fe
Add comprehensive Agent protobuf module tests
Added 37 tests covering all 12 protobuf modules:
- AgentConfig, Equipment, SnmpConfig
- Sensor, Sensor.MetadataEntry, Interface
- MetricBatch, Metric (with oneof field handling)
- SensorReading, InterfaceStat
- HeartbeatMetadata, HeartbeatResponse

Tests cover struct creation, default values, and encode/decode cycles.
All protobuf modules now at 100% coverage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 08:39:02 -06:00
8291c6092a
Add comprehensive AgentController edge case tests
Added 6 new tests covering previously untested scenarios:
- Equipment without SNMP device (nil sensors/interfaces)
- Protobuf metrics with unknown types
- JSON metrics with unknown types
- Metrics with nil timestamps
- Metrics with invalid ISO8601 timestamp strings

Coverage increased from 90.41% to near 100%.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 08:37:58 -06:00
3fe051fd19
Add comprehensive AgentAuth plug tests
Added 8 tests covering all plug functionality:
- init/1 option passing
- Valid token authentication
- Invalid authorization header scenarios
- Malformed Bearer token handling
- Invalid token value rejection
- Asynchronous heartbeat updates
- Token verification error handling

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 08:35:13 -06:00
5bd24b09f9
Add UserNotifier tests
- Test deliver_update_email_instructions/2
- Test deliver_login_instructions/2 for confirmed and unconfirmed users
- Verify email content and recipients
- Coverage remains at 67.05%
2026-01-13 08:25:20 -06:00
df315a897a
Add Monitoring.Supervisor tests
- Test start_monitor/1 and stop_monitor/1
- Test start_snmp_poller/1 and stop_snmp_poller/1
- Test start_all_monitors/0 and start_all_snmp_pollers/0
- Verify process lifecycle management
- Coverage: 67.05% -> 67.09%
2026-01-13 08:21:50 -06:00
3068f944fb
Add TimescaleDB aggregate tests, implement on-demand calculation
- Updated Monitoring module to calculate hourly/daily stats on-demand from monitoring_checks table
- Removed TimescaleDB continuous aggregate dependency (disabled due to licensing)
- Enabled all previously skipped TimescaleDB tests with proper test data
- Fixed UUID encoding for SQL queries using Ecto.UUID.dump!
- Fixed Decimal handling in uptime percentage calculation
- Added test for get_uptime_percentage with nil checks
- Monitoring module now at 100% coverage
2026-01-13 08:09:12 -06:00
43a9ff01a6
Add comprehensive tests for Equipment context
Added 6 new tests to improve coverage:
- list_snmp_enabled_equipment/0 for SNMP-enabled equipment filtering
- update_snmp_poll_time/1 for updating polling timestamps
- create_event/1 for creating equipment events with proper schema
- list_equipment_events/2 for event retrieval and ordering
- list_equipment_events/2 with limit parameter

This improves Equipment coverage from 87.50% to higher.
2026-01-13 08:01:45 -06:00
6cc068543d
Add comprehensive tests for Sites context
Added 5 new tests to improve coverage:
- list_root_sites/1 for filtering root sites without parents
- list_child_sites/1 for getting child sites of a parent
- list_child_sites/1 edge case with no children
- get_site!/1 for verifying preload behavior with parent and child sites

This improves Sites coverage from 83.33% to higher.
2026-01-13 07:59:10 -06:00
b91f81fc2e
Add comprehensive tests for Agents context
Added 9 new tests to expand coverage:
- get_agent_token!/1 success and failure cases
- update_agent_token_heartbeat/3 edge cases (nil and empty metadata)
- get_equipment_assignment/1 for assigned and unassigned equipment
- update_equipment_assignment/2 for creating, updating, and removing assignments

This improves Agents coverage from 89.29% to higher.
2026-01-13 07:54:36 -06:00
f0af777f6e
Add tests for UserSettingsHTML
Added 2 tests covering the edit.html settings form template:
- Settings form rendering with email, password, and passkeys sections
- Warning message when user cannot register passkey

This improves UserSettingsHTML coverage from 0% to 100%.
2026-01-13 07:52:46 -06:00
a430d09668
Add test for UserRegistrationHTML
Added test to cover the new.html registration form template.

This improves UserRegistrationHTML coverage from 0% to 100%.
2026-01-13 07:52:06 -06:00
29c8e1a8d3
Add comprehensive tests for UserSessionHTML
Added 5 tests covering both new.html and confirm.html templates:
- Login form rendering with multiple authentication methods
- Reauthentication message display
- Confirmation form for unconfirmed users
- Login form for confirmed users
- Simplified login for reauthentication with current_scope

This improves UserSessionHTML coverage from 50.00% to 100%.
2026-01-13 07:50:39 -06:00
89b038a14f
Add test for PageHTML home template
Added test to cover the home.html template rendering.

This improves PageHTML coverage from 0% to 100%.
2026-01-13 07:49:25 -06:00
6e02dc460a
Add test for ErrorHTML fallback render function
Added test to cover the fallback render/2 function that handles
error codes without custom templates (401, 403, 503, etc.).

This improves ErrorHTML coverage from 0% to 100%.
2026-01-13 07:48:23 -06:00
7e5da340d3
Add comprehensive tests for Accounts.UserCredential
Improved coverage from 28.57% to 100% by adding 13 tests covering:
- Required field validations (user_id, credential_id, public_key, name)
- Name length validation (min 1, max 100 characters)
- Optional field handling (sign_count, last_used_at, aaguid, transports, backup flags, attestation_format)
- Default values for optional fields
- touch_changeset/1 function (updates last_used_at and increments sign_count)

Overall coverage: 66.44%
2026-01-13 07:47:37 -06:00
f5bef9b997
Add comprehensive tests for Organizations.Invitation
Improved coverage from 60.00% to 100% by adding 13 tests covering:
- Required field validations (email, role, organization_id, invited_by_id)
- Email format validation
- Automatic token generation using crypto
- Token preservation when provided
- Automatic expires_at generation (7 days from now)
- Expires_at preservation when provided
- All valid role values (admin, member, viewer)
- Accepted_at field handling

Overall coverage: 66.34%
2026-01-13 07:45:50 -06:00
160007cab1
Add HealthController test (0% → 100%) 2026-01-13 07:39:28 -06:00
e6650833f6
Improve test coverage: AgentLive.Index, UserAuth, Cisco profile
- Added comprehensive tests for ToweropsWeb.AgentLive.Index
  - Tests mount, create_agent, revoke_agent, and close_token_modal events
  - Tests agent status display and last_seen formatting
  - Coverage improved from 57.50% to 80.00%

- Enhanced ToweropsWeb.UserAuth tests
  - Added tests for impersonation functionality
  - Added tests for organization loading and membership verification
  - Added tests for superuser authorization
  - Coverage improved from 51.08% to 61.87%

- Expanded Towerops.Snmp.Profiles.Cisco tests
  - Added tests for all sensor type parsing functions
  - Added tests for different sensor scales, statuses, and error conditions
  - Tests sensor discovery with various data formats
  - Coverage improved from 57.30% to 100.00%

Overall test coverage improved from 64.25% to 65.86%
2026-01-12 18:56:23 -06:00
7cf3e61709
Add comprehensive tests for EquipmentLive.Form and UserCredentialController
- EquipmentLive.Form: 46.73% → 92.52% (+45.79%)
  - Added 27 tests covering form validation, SNMP testing, site selection
  - Tests mount behavior, save/update flows, deletion, and discovery triggers
  - Tests SNMP config changes and agent assignment

- UserCredentialController: 33.93% → 64.29% (+30.36%)
  - Added 7 tests for WebAuthn registration and authentication flows
  - Tests challenge generation, credential registration, and error cases
  - Tests discoverable authentication and account-specific auth

Overall coverage: 60.40% → 63.67% (+3.27%)
2026-01-12 18:46:15 -06:00
3c41f7e132
Enhance EquipmentLive.Show test coverage with additional test cases
Added 5 new test cases for EquipmentLive.Show module:
- Test with tab parameter (interfaces tab)
- Test equipment status with monitoring checks
- Test SNMP device information display
- Test recent events display
- Test handling of missing equipment

Coverage improvement: ToweropsWeb.EquipmentLive.Show 35.51% → 46.38%
Overall coverage: 59.88% → 60.40%

All 21 tests pass successfully.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-12 18:35:37 -06:00
d21e389b04
Improve test coverage with comprehensive SNMP and monitoring tests
Added extensive test suites to improve overall test coverage from 55.62% to 59.88%:

- Created Towerops.Snmp test suite (38 tests) - coverage: 10.87% → 97.83%
- Created Towerops.Snmp.Profiles.Cisco tests (14 tests) - coverage: 20.22% → 57.30%
- Created Towerops.Snmp.Profiles.NetSnmp tests (13 tests) - coverage: 56.79% → 92.59%
- Created Towerops.Monitoring.Supervisor tests (10 tests) - coverage: 21.21% → 63.64%
- Enhanced Towerops.Monitoring tests with TimescaleDB aggregate tests (skipped in test env)

Tests use Mox for SNMP client mocking with proper mock expectations for get/walk operations.
All tests follow established patterns and pass successfully.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-12 18:31:19 -06:00
36175be74e
fix dialyzer and credo 2026-01-11 15:01:57 -06:00
3ef04f261f
protobufs 2026-01-09 17:33:01 -06:00
cf77949527
add remote agent setup 2026-01-09 13:15:31 -06:00
4f924ba9a7
add passkey 2026-01-09 12:26:32 -06:00
96bd8b3829
add MIB-based validation and generic profile tests
- Add MIB files from LibreNMS in priv/mibs/ for reference
- Create MibParser module to validate OIDs against official MIB definitions
- Add MIB validation tests to ensure hardcoded OIDs match MIB specs
- Refactor SNMP tests to be generic/behavior-focused instead of vendor-specific
- Remove vendor-specific test files (cisco_test, net_snmp_test)
- All 104 tests passing with automated OID validation
2026-01-08 08:57:21 -06:00
d8e29abf09
more tests and logging around email 2026-01-06 16:00:41 -06:00
c3303cc194
moar tests 2026-01-06 15:43:54 -06:00
41dcf3084f
add error pages 2026-01-06 14:37:48 -06:00
3b9fffdd07
add marketing site 2026-01-06 14:34:48 -06:00
a3cd43d2c2
Fix credo warnings and software design suggestions
Replace expensive length/1 comparisons with direct list comparisons or Enum.empty?/1 checks (13 instances in source code and tests). Add module aliases for Phoenix.HTML.Form and Towerops.Accounts.Scope to reduce nested module references.

Changes:
- Replace length(list) > 0 with list != [] or refute Enum.empty?(list)
- Add Phoenix.HTML.Form alias in CoreComponents
- Add Towerops.Accounts.Scope alias in ConnCase test helper

This eliminates all credo warnings and software design suggestions.
2026-01-06 12:55:22 -06:00
13d98ce548
Fix all failing tests after UI changes
- Add EventLogger tests for PubSub event system
- Update navigation tests to match current UI patterns
- Fix alert notifier from address expectations
- Update site and equipment tests for relocated delete buttons
- Remove obsolete tests for removed UI elements (Recent Checks, monitoring widgets)
- All 254 tests now passing
2026-01-05 11:33:26 -06:00
d6a9bb11d7
Redesign equipment view with compact LibreNMS-style dashboard
- Add real-time updates with 10-second refresh and PubSub integration
- Implement pure SVG charts: response time sparkline and uptime gauge
- Create compact dashboard layout with status cards, metrics, and graphs
- Add relative time display (e.g., '5s ago') for last check
- Redesign SNMP data display: compact device info, sensors grid, interfaces table
- Calculate and display uptime percentage and average response time
- Update tests to match new compact layout
2026-01-03 15:11:47 -06:00
8cbca259fc
snmp bits 2026-01-03 14:41:28 -06:00
0f9266027f
fix dialyzer things 2026-01-03 12:56:40 -06:00
5d9ebb14f9
Change organization slugs to random IDs independent of name
- Organization names can now be freely duplicated
- Slugs are generated as random 8-character lowercase alphanumeric IDs
- Provides ~218 trillion possible combinations
- Updated tests to not rely on name-based slug patterns
2026-01-03 12:33:11 -06:00