mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-07 15:01:32 +00:00
8b75e0311b
Mechanical sed across the main go.mod's module declaration, the f5-mock-icontrol
sub-module's go.mod, every Go file's import path (361 files), and a rebuild of
the checked-in f5-mock-icontrol binary so its embedded build-info reflects the
new module path. No behavior change.
Choice B from cowork/transfer-certctl-to-org.md, executed 2026-05-04. Choice A
(keep module path declared as github.com/shankar0123/certctl regardless of
repo URL) shipped on the day of the org transfer (2026-05-03) since we had no
external Go consumers; this commit closes that deferral.
Backward-compat: GitHub HTTP redirects continue to forward
github.com/shankar0123/certctl → github.com/certctl-io/certctl at the URL
level, but Go's module proxy uses the path declared in go.mod as the
canonical name. Pre-fix, anyone trying `go get github.com/certctl-io/certctl/...`
hit a "module path mismatch" error because go.mod said
github.com/shankar0123/certctl and the URL they fetched it from said
certctl-io/certctl. Post-fix, the canonical name and the URL agree, so
go get / go install / external Go consumers / Go-tooling integrations
work cleanly via either the new path (preferred) or the old path (which
redirects and Go follows the redirect for source fetch).
Anyone still importing the old path inside their own code keeps working
provided they update their go.mod's `require` line to match — the module
path declared in their consumer's go.sum / go.mod is the authoritative
import name, so a mass sed across their import statements is the migration
on the consumer side. No external consumers exist today.
Diff shape:
361 *.go files — import path replacement only
2 go.mod — module declaration replacement only
1 binary — deploy/test/f5-mock-icontrol/f5-mock-icontrol rebuilt
so embedded build-info reflects the new path (8618965 vs
8618933 bytes; 32-byte diff is the build-info change)
Total: 364 files, 730 insertions / 730 deletions, net-zero size, pure
mechanical substitution.
Verification:
gofmt: 17 files needed re-alignment after sed (the new path is one char
shorter than the old, so column-aligned import groups drifted). Applied
`gofmt -w` to fix.
go mod tidy: clean exit on both modules.
go vet ./...: clean exit.
go build ./...: clean exit.
go test -short -count=1 on representative packages: all green
(internal/domain, internal/validation, internal/crypto, internal/crypto/signer,
cmd/agent). Test output now reads `ok github.com/certctl-io/certctl/...`
confirming the module path resolves correctly.
binary: f5-mock-icontrol rebuilt; `strings | grep shankar0123` returns
nothing; `strings | grep certctl-io/certctl` shows the new module path
embedded in build-info.
Files intentionally NOT touched in this commit:
README.md / CHANGELOG.md / docs/ / etc. — already swept to certctl-io
URLs in commit 0729ee4 (the post-transfer URL refresh). This commit is
purely the Go-tooling layer.
Scarf pixels (`shankar0123.docker.scarf.sh/...`) — Scarf-account
namespace, not a Go import or GitHub repo URL. Stays.
This is a non-blocking, non-customer-impacting change. Operators pulling
container images, running `make verify`, hitting the API, or installing the
agent see no functional difference. Only Go-tooling consumers (none today)
are affected, and they're enabled — not broken — by this commit.
234 lines
6.6 KiB
Go
234 lines
6.6 KiB
Go
package handler
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/certctl-io/certctl/internal/domain"
|
|
)
|
|
|
|
// mockNetworkScanService implements NetworkScanService for testing.
|
|
type mockNetworkScanService struct {
|
|
targets []*domain.NetworkScanTarget
|
|
}
|
|
|
|
func (m *mockNetworkScanService) ListTargets(ctx context.Context) ([]*domain.NetworkScanTarget, error) {
|
|
return m.targets, nil
|
|
}
|
|
|
|
func (m *mockNetworkScanService) GetTarget(ctx context.Context, id string) (*domain.NetworkScanTarget, error) {
|
|
for _, t := range m.targets {
|
|
if t.ID == id {
|
|
return t, nil
|
|
}
|
|
}
|
|
return nil, fmt.Errorf("not found: %w", ErrMockNotFound)
|
|
}
|
|
|
|
func (m *mockNetworkScanService) CreateTarget(ctx context.Context, target *domain.NetworkScanTarget) (*domain.NetworkScanTarget, error) {
|
|
if target.Name == "" {
|
|
return nil, fmt.Errorf("name is required")
|
|
}
|
|
target.ID = "nst-test-123"
|
|
m.targets = append(m.targets, target)
|
|
return target, nil
|
|
}
|
|
|
|
func (m *mockNetworkScanService) UpdateTarget(ctx context.Context, id string, target *domain.NetworkScanTarget) (*domain.NetworkScanTarget, error) {
|
|
for _, t := range m.targets {
|
|
if t.ID == id {
|
|
if target.Name != "" {
|
|
t.Name = target.Name
|
|
}
|
|
return t, nil
|
|
}
|
|
}
|
|
return nil, fmt.Errorf("not found: %w", ErrMockNotFound)
|
|
}
|
|
|
|
func (m *mockNetworkScanService) DeleteTarget(ctx context.Context, id string) error {
|
|
for i, t := range m.targets {
|
|
if t.ID == id {
|
|
m.targets = append(m.targets[:i], m.targets[i+1:]...)
|
|
return nil
|
|
}
|
|
}
|
|
return fmt.Errorf("not found: %w", ErrMockNotFound)
|
|
}
|
|
|
|
func (m *mockNetworkScanService) TriggerScan(ctx context.Context, targetID string) (*domain.DiscoveryScan, error) {
|
|
for _, t := range m.targets {
|
|
if t.ID == targetID {
|
|
return &domain.DiscoveryScan{
|
|
ID: "dscan-test",
|
|
AgentID: "server-scanner",
|
|
CertificatesFound: 3,
|
|
}, nil
|
|
}
|
|
}
|
|
return nil, fmt.Errorf("not found: %w", ErrMockNotFound)
|
|
}
|
|
|
|
// SCEP RFC 8894 + Intune master bundle Phase 11.5 — interface
|
|
// satisfaction stubs for the SCEP probe methods. The existing mock
|
|
// doesn't exercise the probe path; dedicated tests in
|
|
// scep_probe_handler_test.go (Phase 11.5.F) cover that surface with
|
|
// their own targeted mock.
|
|
func (m *mockNetworkScanService) ProbeSCEP(ctx context.Context, url string) (*domain.SCEPProbeResult, error) {
|
|
return nil, fmt.Errorf("ProbeSCEP not implemented in mockNetworkScanService — use scepProbeMockService")
|
|
}
|
|
|
|
func (m *mockNetworkScanService) ListRecentSCEPProbes(ctx context.Context, limit int) ([]*domain.SCEPProbeResult, error) {
|
|
return []*domain.SCEPProbeResult{}, nil
|
|
}
|
|
|
|
func TestListNetworkScanTargets(t *testing.T) {
|
|
svc := &mockNetworkScanService{
|
|
targets: []*domain.NetworkScanTarget{
|
|
{ID: "nst-1", Name: "target1", CIDRs: []string{"10.0.0.0/24"}, Ports: []int64{443}},
|
|
{ID: "nst-2", Name: "target2", CIDRs: []string{"192.168.0.0/16"}, Ports: []int64{443, 8443}},
|
|
},
|
|
}
|
|
h := NewNetworkScanHandler(svc)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/network-scan-targets", nil)
|
|
w := httptest.NewRecorder()
|
|
h.ListNetworkScanTargets(w, req)
|
|
|
|
if w.Code != http.StatusOK {
|
|
t.Errorf("expected 200, got %d", w.Code)
|
|
}
|
|
|
|
var resp PagedResponse
|
|
json.NewDecoder(w.Body).Decode(&resp)
|
|
if resp.Total != 2 {
|
|
t.Errorf("expected total 2, got %d", resp.Total)
|
|
}
|
|
}
|
|
|
|
func TestListNetworkScanTargets_Empty(t *testing.T) {
|
|
svc := &mockNetworkScanService{}
|
|
h := NewNetworkScanHandler(svc)
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/network-scan-targets", nil)
|
|
w := httptest.NewRecorder()
|
|
h.ListNetworkScanTargets(w, req)
|
|
|
|
if w.Code != http.StatusOK {
|
|
t.Errorf("expected 200, got %d", w.Code)
|
|
}
|
|
}
|
|
|
|
func TestCreateNetworkScanTarget(t *testing.T) {
|
|
svc := &mockNetworkScanService{}
|
|
h := NewNetworkScanHandler(svc)
|
|
|
|
body, _ := json.Marshal(map[string]interface{}{
|
|
"name": "Production",
|
|
"cidrs": []string{"10.0.0.0/24"},
|
|
"ports": []int64{443},
|
|
})
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/network-scan-targets", bytes.NewReader(body))
|
|
w := httptest.NewRecorder()
|
|
h.CreateNetworkScanTarget(w, req)
|
|
|
|
if w.Code != http.StatusCreated {
|
|
t.Errorf("expected 201, got %d: %s", w.Code, w.Body.String())
|
|
}
|
|
}
|
|
|
|
func TestCreateNetworkScanTarget_InvalidJSON(t *testing.T) {
|
|
svc := &mockNetworkScanService{}
|
|
h := NewNetworkScanHandler(svc)
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/network-scan-targets", bytes.NewReader([]byte("not json")))
|
|
w := httptest.NewRecorder()
|
|
h.CreateNetworkScanTarget(w, req)
|
|
|
|
if w.Code != http.StatusBadRequest {
|
|
t.Errorf("expected 400, got %d", w.Code)
|
|
}
|
|
}
|
|
|
|
func TestCreateNetworkScanTarget_MissingName(t *testing.T) {
|
|
svc := &mockNetworkScanService{}
|
|
h := NewNetworkScanHandler(svc)
|
|
|
|
body, _ := json.Marshal(map[string]interface{}{
|
|
"cidrs": []string{"10.0.0.0/24"},
|
|
})
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/network-scan-targets", bytes.NewReader(body))
|
|
w := httptest.NewRecorder()
|
|
h.CreateNetworkScanTarget(w, req)
|
|
|
|
if w.Code != http.StatusBadRequest {
|
|
t.Errorf("expected 400, got %d", w.Code)
|
|
}
|
|
}
|
|
|
|
func TestDeleteNetworkScanTarget_NotFound(t *testing.T) {
|
|
svc := &mockNetworkScanService{}
|
|
h := NewNetworkScanHandler(svc)
|
|
|
|
req := httptest.NewRequest(http.MethodDelete, "/api/v1/network-scan-targets/nst-nonexistent", nil)
|
|
req.SetPathValue("id", "nst-nonexistent")
|
|
w := httptest.NewRecorder()
|
|
h.DeleteNetworkScanTarget(w, req)
|
|
|
|
if w.Code != http.StatusNotFound {
|
|
t.Errorf("expected 404, got %d", w.Code)
|
|
}
|
|
}
|
|
|
|
func TestTriggerNetworkScan(t *testing.T) {
|
|
svc := &mockNetworkScanService{
|
|
targets: []*domain.NetworkScanTarget{
|
|
{ID: "nst-1", Name: "target1"},
|
|
},
|
|
}
|
|
h := NewNetworkScanHandler(svc)
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/network-scan-targets/nst-1/scan", nil)
|
|
req.SetPathValue("id", "nst-1")
|
|
w := httptest.NewRecorder()
|
|
h.TriggerNetworkScan(w, req)
|
|
|
|
if w.Code != http.StatusAccepted {
|
|
t.Errorf("expected 202, got %d: %s", w.Code, w.Body.String())
|
|
}
|
|
}
|
|
|
|
func TestTriggerNetworkScan_NotFound(t *testing.T) {
|
|
svc := &mockNetworkScanService{}
|
|
h := NewNetworkScanHandler(svc)
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/network-scan-targets/nst-nonexistent/scan", nil)
|
|
req.SetPathValue("id", "nst-nonexistent")
|
|
w := httptest.NewRecorder()
|
|
h.TriggerNetworkScan(w, req)
|
|
|
|
if w.Code != http.StatusInternalServerError {
|
|
t.Errorf("expected 500, got %d", w.Code)
|
|
}
|
|
}
|
|
|
|
func TestListNetworkScanTargets_MethodNotAllowed(t *testing.T) {
|
|
svc := &mockNetworkScanService{}
|
|
h := NewNetworkScanHandler(svc)
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/network-scan-targets", nil)
|
|
w := httptest.NewRecorder()
|
|
h.ListNetworkScanTargets(w, req)
|
|
|
|
if w.Code != http.StatusMethodNotAllowed {
|
|
t.Errorf("expected 405, got %d", w.Code)
|
|
}
|
|
}
|