Add CORS support and response caching to aggregate endpoints
- Introduced CORS configuration options in config.example.yaml, allowing specification of allowed origins for cross-origin requests. - Enhanced the aggregate handler to support response caching with a configurable TTL, improving performance for repeated requests. - Updated the aggregate API to return a structured response indicating whether any upstream requests failed, enhancing error handling and response clarity. - Modified documentation in AGGREGATE.md and README.md to reflect the new CORS and caching features. - Added tests to validate the new functionality in the aggregate handler.
This commit is contained in:
@@ -119,6 +119,55 @@ func TestBuildSummary(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildUsersMergeLimits(t *testing.T) {
|
||||
tag1 := "aa"
|
||||
tag2 := "bb"
|
||||
expLater := "2030-01-02T00:00:00Z"
|
||||
expEarlier := "2020-01-02T00:00:00Z"
|
||||
m20 := uint64(20)
|
||||
m10 := uint64(10)
|
||||
q500 := uint64(500)
|
||||
q100 := uint64(100)
|
||||
results := []ServerFetchResult{
|
||||
{
|
||||
Alias: "b", OK: true,
|
||||
Users: []UserInfo{{
|
||||
Username: "u", TotalOctets: 1, CurrentConnections: 0,
|
||||
UserAdTag: &tag2, MaxTCPConns: &m20, ExpirationRFC3339: &expLater,
|
||||
DataQuotaBytes: &q500, MaxUniqueIPs: &m10,
|
||||
}},
|
||||
},
|
||||
{
|
||||
Alias: "a", OK: true,
|
||||
Users: []UserInfo{{
|
||||
Username: "u", TotalOctets: 1, CurrentConnections: 0,
|
||||
UserAdTag: &tag1, MaxTCPConns: &m10, ExpirationRFC3339: &expEarlier,
|
||||
DataQuotaBytes: &q100, MaxUniqueIPs: &m20,
|
||||
}},
|
||||
},
|
||||
}
|
||||
rows := BuildUsers(results, false, 0)
|
||||
if len(rows) != 1 {
|
||||
t.Fatalf("rows: %+v", rows)
|
||||
}
|
||||
r := rows[0]
|
||||
if r.UserAdTag == nil || *r.UserAdTag != tag1 {
|
||||
t.Fatalf("ad tag want first alias order a: got %v", r.UserAdTag)
|
||||
}
|
||||
if r.MaxTCPConns == nil || *r.MaxTCPConns != 10 {
|
||||
t.Fatalf("max tcp want min 10: %v", r.MaxTCPConns)
|
||||
}
|
||||
if r.ExpirationRFC3339 == nil || *r.ExpirationRFC3339 != expEarlier {
|
||||
t.Fatalf("expiration want earliest: %v", r.ExpirationRFC3339)
|
||||
}
|
||||
if r.DataQuotaBytes == nil || *r.DataQuotaBytes != 100 {
|
||||
t.Fatalf("quota want min: %v", r.DataQuotaBytes)
|
||||
}
|
||||
if r.MaxUniqueIPs == nil || *r.MaxUniqueIPs != 10 {
|
||||
t.Fatalf("max unique ips want min: %v", r.MaxUniqueIPs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildUsersMinOctets(t *testing.T) {
|
||||
results := []ServerFetchResult{
|
||||
{Alias: "a", OK: true, Users: []UserInfo{{Username: "low", TotalOctets: 5}}},
|
||||
|
||||
Reference in New Issue
Block a user