Skip to content

Commit

Permalink
remove dead test
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Jan 16, 2025
1 parent 6425ba3 commit 83c8e70
Showing 1 changed file with 0 additions and 135 deletions.
135 changes: 0 additions & 135 deletions fronted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,141 +506,6 @@ func TestPassthrough(t *testing.T) {
}
}

func TestCustomValidators(t *testing.T) {

sadCloud, sadCloudAddr, err := newCDN("sadcloud", "sadcloud.io")
if !assert.NoError(t, err, "failed to start sadcloud cdn") {
return
}
defer sadCloud.Close()

sadCloudCodes := []int{http.StatusPaymentRequired, http.StatusTeapot, http.StatusBadGateway}
sadCloudValidator := NewStatusCodeValidator(sadCloudCodes)
testURL := "https://abc.forbidden.com/quux"

setup := func(validator ResponseValidator) (Fronted, error) {
masq := []*Masquerade{{Domain: "example.com", IpAddress: sadCloudAddr}}
alias := map[string]string{
"abc.forbidden.com": "abc.sadcloud.io",
}
p := NewProvider(alias, "https://ttt.sadcloud.io/ping", masq, nil, nil, nil, "")

certs := x509.NewCertPool()
certs.AddCert(sadCloud.Certificate())

providers := map[string]*Provider{
"sadcloud": p,
}

defaultFrontedProviderID = "sadcloud"
f := NewFronted()
f.OnNewFronts(certs, providers)
return f, nil
}

// This error indicates that the validator has discarded all masquerades.
// Each test starts with one masquerade, which is vetted during the
// call to NewDirect.
masqueradesExhausted := fmt.Sprintf(`Get "%v": could not complete request even with retries`, testURL)

tests := []struct {
name string
responseCode int
validator ResponseValidator
expectedError string
}{
// with the default validator, only 403s are rejected
{
name: "with default validator, it should reject 403",
responseCode: http.StatusForbidden,
validator: nil,
expectedError: masqueradesExhausted,
},
{
name: "with default validator, it should accept 202",
responseCode: http.StatusAccepted,
validator: nil,
expectedError: "",
},
{
name: "with default validator, it should accept 402",
responseCode: http.StatusPaymentRequired,
validator: nil,
expectedError: "",
},
{
name: "with default validator, it should accept 418",
responseCode: http.StatusTeapot,
validator: nil,
expectedError: "",
},
{
name: "with default validator, it should accept 502",
responseCode: http.StatusBadGateway,
validator: nil,
expectedError: "",
},

// with the custom validator, 403 is allowed, listed codes are rejected
{
name: "with custom validator, it should accept 403",
responseCode: http.StatusForbidden,
validator: sadCloudValidator,
expectedError: "",
},
{
name: "with custom validator, it should accept 402",
responseCode: http.StatusAccepted,
validator: sadCloudValidator,
expectedError: "",
},
{
name: "with custom validator, it should reject and return error for 402",
responseCode: http.StatusPaymentRequired,
validator: sadCloudValidator,
expectedError: masqueradesExhausted,
},
{
name: "with custom validator, it should reject and return error for 418",
responseCode: http.StatusTeapot,
validator: sadCloudValidator,
expectedError: masqueradesExhausted,
},
{
name: "with custom validator, it should reject and return error for 502",
responseCode: http.StatusBadGateway,
validator: sadCloudValidator,
expectedError: masqueradesExhausted,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
direct, err := setup(test.validator)
require.NoError(t, err)
client := &http.Client{
Transport: direct,
}

req, err := http.NewRequest(http.MethodGet, testURL, nil)
require.NoError(t, err)
if test.responseCode != http.StatusAccepted {
val := strconv.Itoa(test.responseCode)
log.Debugf("requesting forced response code %s", val)
req.Header.Set(CDNForceFail, val)
}

res, err := client.Do(req)
if test.expectedError == "" {
require.NoError(t, err)
assert.Equal(t, test.responseCode, res.StatusCode, "Failed to force response status code")
} else {
assert.EqualError(t, err, test.expectedError)
}
})
}
}

const (
// set this header to an integer to force response status code
CDNForceFail = "X-CDN-Force-Fail"
Expand Down

0 comments on commit 83c8e70

Please sign in to comment.