mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-10-25 06:57:26 +00:00
chore(security,refactor): extract sanitization and improve code quality (#41)
* chore(security,refactor): extract sanitization and improve code quality
- [x] Extract sanitization functions to dedicated sanitization.go module
- [x] Add comprehensive golangci-lint v2 configuration with security rules
- [x] Replace interface{} with any type throughout codebase
- [x] Add admin API authentication security warning
- [x] Extract WebSocket and stats streaming constants
- [x] Add best-effort error handling comments for resource cleanup
- [x] Expand sensitive field patterns for improved PII redaction
- [x] Simplify safety checks and remove redundant nil validations
- [x] Improve test coverage for password field redaction patterns
* refactor: replace interface{} with any type alias
- [x] Replace all `map[string]interface{}` with `map[string]any`
- [x] Replace all `interface{}` with `any` in function signatures and type definitions
- [x] Update sync.Pool New function returns from `interface{}` to `any`
- [x] Add package documentation comments to 8 package files
- [x] Update type assertions and casts to work with `any` type
This commit is contained in:
@@ -25,7 +25,7 @@ func (suite *CircuitBreakerTestSuite) TestCircuitBreakerStateTransitions() {
|
||||
// 2. Generate failures to trip the circuit
|
||||
testErr := errors.New("test error")
|
||||
for i := 0; i < cfg.CircuitBreaker.MaxFailures; i++ {
|
||||
_, err := cb.Execute(func() (interface{}, error) {
|
||||
_, err := cb.Execute(func() (any, error) {
|
||||
return nil, testErr
|
||||
})
|
||||
assert.Error(suite.T(), err, "Execute should return error")
|
||||
@@ -35,7 +35,7 @@ func (suite *CircuitBreakerTestSuite) TestCircuitBreakerStateTransitions() {
|
||||
assert.Equal(suite.T(), gobreaker.StateOpen.String(), cb.State().String(), "Circuit should transition to open state after failures")
|
||||
|
||||
// Verify that requests are rejected during open state
|
||||
_, err := cb.Execute(func() (interface{}, error) {
|
||||
_, err := cb.Execute(func() (any, error) {
|
||||
return "success", nil
|
||||
})
|
||||
assert.Equal(suite.T(), gobreaker.ErrOpenState.Error(), err.Error(), "Should return ErrOpenState when circuit is open")
|
||||
@@ -55,7 +55,7 @@ func (suite *CircuitBreakerTestSuite) TestCircuitBreakerStateTransitions() {
|
||||
// (Sony's gobreaker transitions to half-open on the next request after timeout)
|
||||
tmpState := cb.State()
|
||||
// Execute a successful request to check state
|
||||
_, _ = cb.Execute(func() (interface{}, error) {
|
||||
_, _ = cb.Execute(func() (any, error) {
|
||||
return "success", nil
|
||||
})
|
||||
|
||||
@@ -73,7 +73,7 @@ func (suite *CircuitBreakerTestSuite) TestCircuitBreakerStateTransitions() {
|
||||
|
||||
// 6. Execute successful requests in half-open state to transition back to closed
|
||||
for i := 0; i < cfg.CircuitBreaker.MaxRequestsInHalfOpen; i++ {
|
||||
_, err = cb.Execute(func() (interface{}, error) {
|
||||
_, err = cb.Execute(func() (any, error) {
|
||||
return "success", nil
|
||||
})
|
||||
assert.NoError(suite.T(), err, "Execute should not return error")
|
||||
@@ -104,7 +104,7 @@ func (suite *CircuitBreakerTestSuite) TestCircuitBreakerHalfOpenToOpen() {
|
||||
// 1. Generate failures to trip the circuit
|
||||
testErr := errors.New("test error")
|
||||
for i := 0; i < cfg.CircuitBreaker.MaxFailures; i++ {
|
||||
_, err := cb.Execute(func() (interface{}, error) {
|
||||
_, err := cb.Execute(func() (any, error) {
|
||||
return nil, testErr
|
||||
})
|
||||
assert.Error(suite.T(), err, "Execute should return error")
|
||||
@@ -119,7 +119,7 @@ func (suite *CircuitBreakerTestSuite) TestCircuitBreakerHalfOpenToOpen() {
|
||||
// The next request should transition the circuit to half-open
|
||||
tmpState := cb.State()
|
||||
// Try a request that will fail
|
||||
_, _ = cb.Execute(func() (interface{}, error) {
|
||||
_, _ = cb.Execute(func() (any, error) {
|
||||
return nil, testErr
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user