fix(identity): 避免未配置 SSF 时触发空指针
SecurityEventReceiver 不再把空 ConnectionManager 包装为非空接口;未启用 SSF 时公开端点明确返回 404。补充运行时和 HTTP 回归测试。\n\n验证:go test ./internal/identityruntime ./internal/httpapi。
This commit is contained in:
@@ -40,6 +40,18 @@ func TestReceiveSecurityEventUsesPreparedReceiverBeforeFirstActivation(t *testin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReceiveSecurityEventReturnsNotFoundWithoutConfiguredReceiver(t *testing.T) {
|
||||||
|
server := &Server{identityRuntime: identityruntime.NewManager(nil, &preparedReceiverBuilder{})}
|
||||||
|
request := httptest.NewRequest(http.MethodPost, "/api/v1/security-events/ssf", nil)
|
||||||
|
response := httptest.NewRecorder()
|
||||||
|
|
||||||
|
server.receiveSecurityEvent(response, request)
|
||||||
|
|
||||||
|
if response.Code != http.StatusNotFound {
|
||||||
|
t.Fatalf("unconfigured SSF status=%d, want %d", response.Code, http.StatusNotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSecurityEventWriteAuditFailsClosedBeforeMutation(t *testing.T) {
|
func TestSecurityEventWriteAuditFailsClosedBeforeMutation(t *testing.T) {
|
||||||
server := &Server{}
|
server := &Server{}
|
||||||
request := httptest.NewRequest(http.MethodPost, "/api/admin/system/security-events/connection/verify", nil)
|
request := httptest.NewRequest(http.MethodPost, "/api/admin/system/security-events/connection/verify", nil)
|
||||||
|
|||||||
@@ -105,7 +105,10 @@ func (manager *Manager) SecurityEventReceiver() http.Handler {
|
|||||||
if runtime := manager.Current(); runtime != nil && runtime.SecurityEvents != nil {
|
if runtime := manager.Current(); runtime != nil && runtime.SecurityEvents != nil {
|
||||||
return runtime.SecurityEvents
|
return runtime.SecurityEvents
|
||||||
}
|
}
|
||||||
return manager.SecurityEventManager()
|
if securityEventManager := manager.SecurityEventManager(); securityEventManager != nil {
|
||||||
|
return securityEventManager
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SecurityEventManager resolves the manager used by administrative recovery
|
// SecurityEventManager resolves the manager used by administrative recovery
|
||||||
|
|||||||
@@ -630,6 +630,14 @@ func TestSecurityEventManagerExposesPreparedRecoveryManagerWithoutActiveRuntime(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSecurityEventReceiverReturnsNilWithoutConfiguredManager(t *testing.T) {
|
||||||
|
manager := NewManager(&runtimeRepositoryFake{}, &runtimeBuilderFake{})
|
||||||
|
|
||||||
|
if manager.SecurityEventReceiver() != nil {
|
||||||
|
t.Fatal("unconfigured security event receiver should be nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSecurityEventManagerPrefersActiveRuntime(t *testing.T) {
|
func TestSecurityEventManagerPrefersActiveRuntime(t *testing.T) {
|
||||||
active := &securityevents.ConnectionManager{}
|
active := &securityevents.ConnectionManager{}
|
||||||
prepared := &securityevents.ConnectionManager{}
|
prepared := &securityevents.ConnectionManager{}
|
||||||
|
|||||||
Reference in New Issue
Block a user