forked from baron/baron-sso
golangci lint 적용
This commit is contained in:
@@ -14,9 +14,11 @@ import (
|
|||||||
|
|
||||||
// Mock services
|
// Mock services
|
||||||
type mockEmailService struct{}
|
type mockEmailService struct{}
|
||||||
|
|
||||||
func (m *mockEmailService) SendEmail(to, subject, body string) error { return nil }
|
func (m *mockEmailService) SendEmail(to, subject, body string) error { return nil }
|
||||||
|
|
||||||
type mockSmsService struct{}
|
type mockSmsService struct{}
|
||||||
|
|
||||||
func (m *mockSmsService) SendSms(to, content string) error { return nil }
|
func (m *mockSmsService) SendSms(to, content string) error { return nil }
|
||||||
|
|
||||||
func TestEnchantedLinkFlow_Email_Success(t *testing.T) {
|
func TestEnchantedLinkFlow_Email_Success(t *testing.T) {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func TestVerifySignupCode_Invalid(t *testing.T) {
|
|||||||
app.Post("/api/v1/auth/signup/verify", h.VerifySignupCode)
|
app.Post("/api/v1/auth/signup/verify", h.VerifySignupCode)
|
||||||
|
|
||||||
stateJSON, _ := json.Marshal(map[string]interface{}{
|
stateJSON, _ := json.Marshal(map[string]interface{}{
|
||||||
"code": "111111",
|
"code": "111111",
|
||||||
"expires_at": 9999999999,
|
"expires_at": 9999999999,
|
||||||
})
|
})
|
||||||
redis.data["signup:email:user@test.com"] = string(stateJSON)
|
redis.data["signup:email:user@test.com"] = string(stateJSON)
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ type mockRedisRepo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockRedisRepo) Set(key, value string, ttl time.Duration) error {
|
func (m *mockRedisRepo) Set(key, value string, ttl time.Duration) error {
|
||||||
if m.data == nil { m.data = make(map[string]string) }
|
if m.data == nil {
|
||||||
|
m.data = make(map[string]string)
|
||||||
|
}
|
||||||
m.data[key] = value
|
m.data[key] = value
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -43,11 +45,11 @@ func (m *mockRedisRepo) StoreVerificationCode(phone, code string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockRedisRepo) GetVerificationCode(phone string) (string, error) {
|
func (m *mockRedisRepo) GetVerificationCode(phone string) (string, error) {
|
||||||
return m.Get("sms:"+phone)
|
return m.Get("sms:" + phone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockRedisRepo) DeleteVerificationCode(phone string) error {
|
func (m *mockRedisRepo) DeleteVerificationCode(phone string) error {
|
||||||
return m.Delete("sms:"+phone)
|
return m.Delete("sms:" + phone)
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Tests ---
|
// --- Tests ---
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ import (
|
|||||||
// --- Mock IDP Provider ---
|
// --- Mock IDP Provider ---
|
||||||
|
|
||||||
type mockIdpProvider struct {
|
type mockIdpProvider struct {
|
||||||
userExists bool
|
userExists bool
|
||||||
name string
|
name string
|
||||||
signInInfo *domain.AuthInfo
|
signInInfo *domain.AuthInfo
|
||||||
issueSession *domain.AuthInfo
|
issueSession *domain.AuthInfo
|
||||||
verifyCodeInfo *domain.AuthInfo
|
verifyCodeInfo *domain.AuthInfo
|
||||||
err error
|
err error
|
||||||
initiateLinkErr error
|
initiateLinkErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockIdpProvider) Name() string {
|
func (m *mockIdpProvider) Name() string {
|
||||||
@@ -32,6 +32,7 @@ func (m *mockIdpProvider) GetMetadata() (*domain.IDPMetadata, error) { return ni
|
|||||||
func (m *mockIdpProvider) CreateUser(user *domain.BrokerUser, password string) (string, error) {
|
func (m *mockIdpProvider) CreateUser(user *domain.BrokerUser, password string) (string, error) {
|
||||||
return "mock-user-id", m.err
|
return "mock-user-id", m.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockIdpProvider) SignIn(loginID, password string) (*domain.AuthInfo, error) {
|
func (m *mockIdpProvider) SignIn(loginID, password string) (*domain.AuthInfo, error) {
|
||||||
return m.signInInfo, m.err
|
return m.signInInfo, m.err
|
||||||
}
|
}
|
||||||
@@ -44,20 +45,23 @@ func (m *mockIdpProvider) IssueSession(loginID string) (*domain.AuthInfo, error)
|
|||||||
SessionToken: &domain.Token{JWT: "valid-jwt", SessionID: "valid-sid"},
|
SessionToken: &domain.Token{JWT: "valid-jwt", SessionID: "valid-sid"},
|
||||||
}, m.err
|
}, m.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockIdpProvider) InitiateLinkLogin(loginID, returnTo string) (*domain.LinkLoginInit, error) {
|
func (m *mockIdpProvider) InitiateLinkLogin(loginID, returnTo string) (*domain.LinkLoginInit, error) {
|
||||||
if m.initiateLinkErr != nil {
|
if m.initiateLinkErr != nil {
|
||||||
return nil, m.initiateLinkErr
|
return nil, m.initiateLinkErr
|
||||||
}
|
}
|
||||||
return &domain.LinkLoginInit{FlowID: "mock-flow-id", Mode: "code"}, m.err
|
return &domain.LinkLoginInit{FlowID: "mock-flow-id", Mode: "code"}, m.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockIdpProvider) VerifyLoginCode(loginID, flowID, code string) (*domain.AuthInfo, error) {
|
func (m *mockIdpProvider) VerifyLoginCode(loginID, flowID, code string) (*domain.AuthInfo, error) {
|
||||||
return m.verifyCodeInfo, m.err
|
return m.verifyCodeInfo, m.err
|
||||||
}
|
}
|
||||||
func (m *mockIdpProvider) GetPasswordPolicy() (*domain.PasswordPolicy, error) { return nil, m.err }
|
func (m *mockIdpProvider) GetPasswordPolicy() (*domain.PasswordPolicy, error) { return nil, m.err }
|
||||||
func (m *mockIdpProvider) InitiatePasswordReset(loginID, redirectUrl string) error { return m.err }
|
func (m *mockIdpProvider) InitiatePasswordReset(loginID, redirectUrl string) error { return m.err }
|
||||||
func (m *mockIdpProvider) VerifyPasswordResetToken(token string) (*domain.AuthInfo, error) {
|
func (m *mockIdpProvider) VerifyPasswordResetToken(token string) (*domain.AuthInfo, error) {
|
||||||
return nil, m.err
|
return nil, m.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockIdpProvider) UpdateUserPassword(loginID, newPassword string, r *http.Request) error {
|
func (m *mockIdpProvider) UpdateUserPassword(loginID, newPassword string, r *http.Request) error {
|
||||||
return m.err
|
return m.err
|
||||||
}
|
}
|
||||||
@@ -72,9 +76,11 @@ func (m *mockAuditRepo) Create(log *domain.AuditLog) error {
|
|||||||
m.logs = append(m.logs, *log)
|
m.logs = append(m.logs, *log)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockAuditRepo) FindPage(ctx context.Context, limit int, cursor *domain.AuditCursor) ([]domain.AuditLog, error) {
|
func (m *mockAuditRepo) FindPage(ctx context.Context, limit int, cursor *domain.AuditCursor) ([]domain.AuditLog, error) {
|
||||||
return m.logs, nil
|
return m.logs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockAuditRepo) FindByUserAndEvents(ctx context.Context, userID string, eventTypes []string, limit int) ([]domain.AuditLog, error) {
|
func (m *mockAuditRepo) FindByUserAndEvents(ctx context.Context, userID string, eventTypes []string, limit int) ([]domain.AuditLog, error) {
|
||||||
var results []domain.AuditLog
|
var results []domain.AuditLog
|
||||||
for _, log := range m.logs {
|
for _, log := range m.logs {
|
||||||
@@ -101,6 +107,7 @@ func (m *mockConsentRepo) Upsert(ctx context.Context, consent *domain.ClientCons
|
|||||||
m.consents = append(m.consents, *consent)
|
m.consents = append(m.consents, *consent)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockConsentRepo) ListBySubject(ctx context.Context, subject string) ([]domain.ClientConsent, error) {
|
func (m *mockConsentRepo) ListBySubject(ctx context.Context, subject string) ([]domain.ClientConsent, error) {
|
||||||
var results []domain.ClientConsent
|
var results []domain.ClientConsent
|
||||||
for _, c := range m.consents {
|
for _, c := range m.consents {
|
||||||
@@ -114,6 +121,7 @@ func (m *mockConsentRepo) Delete(ctx context.Context, clientID, subject string)
|
|||||||
func (m *mockConsentRepo) List(ctx context.Context, clientID string, limit, offset int) ([]domain.ClientConsentWithTenantInfo, int64, error) {
|
func (m *mockConsentRepo) List(ctx context.Context, clientID string, limit, offset int) ([]domain.ClientConsentWithTenantInfo, int64, error) {
|
||||||
return nil, 0, nil
|
return nil, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockConsentRepo) ListByTenant(ctx context.Context, clientID, tenantID string, limit, offset int) ([]domain.ClientConsentWithTenantInfo, int64, error) {
|
func (m *mockConsentRepo) ListByTenant(ctx context.Context, clientID, tenantID string, limit, offset int) ([]domain.ClientConsentWithTenantInfo, int64, error) {
|
||||||
return nil, 0, nil
|
return nil, 0, nil
|
||||||
}
|
}
|
||||||
@@ -125,13 +133,17 @@ type mockSecretRepo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSecretRepo) Upsert(ctx context.Context, clientID, secret string) error {
|
func (m *mockSecretRepo) Upsert(ctx context.Context, clientID, secret string) error {
|
||||||
if m.secrets == nil { m.secrets = make(map[string]string) }
|
if m.secrets == nil {
|
||||||
|
m.secrets = make(map[string]string)
|
||||||
|
}
|
||||||
m.secrets[clientID] = secret
|
m.secrets[clientID] = secret
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSecretRepo) GetByID(ctx context.Context, clientID string) (string, error) {
|
func (m *mockSecretRepo) GetByID(ctx context.Context, clientID string) (string, error) {
|
||||||
return m.secrets[clientID], nil
|
return m.secrets[clientID], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSecretRepo) Delete(ctx context.Context, clientID string) error {
|
func (m *mockSecretRepo) Delete(ctx context.Context, clientID string) error {
|
||||||
delete(m.secrets, clientID)
|
delete(m.secrets, clientID)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func TestListClients_Success(t *testing.T) {
|
|||||||
{"client_id": "client-2", "client_name": "App Two", "metadata": map[string]interface{}{"status": "inactive"}},
|
{"client_id": "client-2", "client_name": "App Two", "metadata": map[string]interface{}{"status": "inactive"}},
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
return httpJSONAny(r, http.StatusNotFound, map[string]string{"error":"not found"}), nil
|
return httpJSONAny(r, http.StatusNotFound, map[string]string{"error": "not found"}), nil
|
||||||
})
|
})
|
||||||
|
|
||||||
h := &DevHandler{
|
h := &DevHandler{
|
||||||
@@ -55,7 +55,7 @@ func TestGetClient_Success(t *testing.T) {
|
|||||||
"metadata": map[string]interface{}{"status": "active"},
|
"metadata": map[string]interface{}{"status": "active"},
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
return httpJSONAny(r, http.StatusNotFound, map[string]string{"error":"not found"}), nil
|
return httpJSONAny(r, http.StatusNotFound, map[string]string{"error": "not found"}), nil
|
||||||
})
|
})
|
||||||
|
|
||||||
h := &DevHandler{
|
h := &DevHandler{
|
||||||
@@ -82,7 +82,7 @@ func TestGetClient_Success(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetClient_NotFound(t *testing.T) {
|
func TestGetClient_NotFound(t *testing.T) {
|
||||||
transport := roundTripFunc(func(r *http.Request) (*http.Response, error) {
|
transport := roundTripFunc(func(r *http.Request) (*http.Response, error) {
|
||||||
return httpJSONAny(r, http.StatusNotFound, map[string]string{"error":"not found"}), nil
|
return httpJSONAny(r, http.StatusNotFound, map[string]string{"error": "not found"}), nil
|
||||||
})
|
})
|
||||||
|
|
||||||
h := &DevHandler{
|
h := &DevHandler{
|
||||||
@@ -109,7 +109,7 @@ func TestCreateClient_Success(t *testing.T) {
|
|||||||
"client_secret": "secret-123",
|
"client_secret": "secret-123",
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
return httpJSONAny(r, http.StatusInternalServerError, map[string]string{"error":"hydra error"}), nil
|
return httpJSONAny(r, http.StatusInternalServerError, map[string]string{"error": "hydra error"}), nil
|
||||||
})
|
})
|
||||||
|
|
||||||
secretRepo := &mockSecretRepo{secrets: make(map[string]string)}
|
secretRepo := &mockSecretRepo{secrets: make(map[string]string)}
|
||||||
@@ -127,8 +127,8 @@ func TestCreateClient_Success(t *testing.T) {
|
|||||||
app.Post("/api/v1/dev/clients", h.CreateClient)
|
app.Post("/api/v1/dev/clients", h.CreateClient)
|
||||||
|
|
||||||
body, _ := json.Marshal(map[string]interface{}{
|
body, _ := json.Marshal(map[string]interface{}{
|
||||||
"client_name": "New App",
|
"client_name": "New App",
|
||||||
"type": "confidential",
|
"type": "confidential",
|
||||||
"redirectUris": []string{"http://localhost/cb"},
|
"redirectUris": []string{"http://localhost/cb"},
|
||||||
})
|
})
|
||||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/dev/clients", bytes.NewReader(body))
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/dev/clients", bytes.NewReader(body))
|
||||||
|
|||||||
Reference in New Issue
Block a user