MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / TestEnrollTokenExpired

Function TestEnrollTokenExpired

internal/serverapi/enroll_test.go:141–163  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

139}
140
141func TestEnrollTokenExpired(t *testing.T) {
142 ca := newTestCA(t)
143 store := enrolltokens.NewMemoryStore()
144 ctx := context.Background()
145 tok := enrolltokens.Token{Token: "tk-exp", NodeID: "n", ExpiresAt: time.Now().Add(-time.Minute)}
146 _ = store.Insert(ctx, tok)
147
148 // Sanity: confirm Consume reports expired.
149 if _, err := store.Consume(ctx, tok.Token); !errors.Is(err, enrolltokens.ErrExpired) {
150 t.Fatalf("expected ErrExpired, got %v", err)
151 }
152 // Re-insert (Consume above doesn't delete) - actually Consume on expired doesn't mark consumed in memory store.
153 // But to keep this test self-contained, build a fresh store:
154 store = enrolltokens.NewMemoryStore()
155 _ = store.Insert(ctx, tok)
156
157 mux := http.NewServeMux()
158 RegisterEnrollEndpoint(mux, ca, store, "")
159 w := doEnroll(t, mux, enrollRequest{NodeID: "n", CSRPem: newTestCSR(t, "n"), Token: tok.Token})
160 if w.Code != http.StatusUnauthorized {
161 t.Fatalf("status=%d", w.Code)
162 }
163}
164
165func TestEnrollNodeIDMismatch(t *testing.T) {
166 ca := newTestCA(t)

Callers

nothing calls this directly

Calls 8

InsertMethod · 0.95
ConsumeMethod · 0.95
NewMemoryStoreFunction · 0.92
RegisterEnrollEndpointFunction · 0.85
doEnrollFunction · 0.85
newTestCSRFunction · 0.85
AddMethod · 0.80
newTestCAFunction · 0.70

Tested by

no test coverage detected