Skip to content

Commit

Permalink
test: anonymize the IDs used
Browse files Browse the repository at this point in the history
Anonymizes the IDs used for service authorizations as well as adds a new
"default" id for user, which can be anonymized to a default User ID in
the `fix-fixtures` target of the makefile.
  • Loading branch information
noseglid committed Jun 16, 2022
1 parent 4a3d7c2 commit e172702
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 62 deletions.
16 changes: 16 additions & 0 deletions fastly/fastly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ var testStatsClient = NewRealtimeStatsClient()
// testServiceID is the ID of the testing service.
var testServiceID = serviceIDForTest()

// testUserID is the ID of the testing user.
var testUserID = userIDForTest()

// Default ID of the testing service.
var defaultTestServiceID = "7i6HN3TK9wS159v2gPAZ8A"

// Default ID of the testing user.
var defaultTestUserID = "4tKBSuFhNEiIpNDxmmVydt"

const (
// ServiceTypeVCL is the type for VCL services.
ServiceTypeVCL = "vcl"
Expand All @@ -43,6 +49,16 @@ func serviceIDForTest() string {
return defaultTestServiceID
}

func userIDForTest() string {
uid := os.Getenv("FASTLY_TEST_USER_ID")

if uid != "" {
return uid
}

return defaultTestUserID
}

func vcrDisabled() bool {
vcrDisable := os.Getenv("VCR_DISABLE")

Expand Down
24 changes: 14 additions & 10 deletions fastly/fixtures/service_authorizations/cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,39 @@ interactions:
headers:
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/RpPAg3cWoOTz6WbzXkA2a
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
method: DELETE
response:
body: ""
body: '{"msg":"Record not found","detail":"Cannot find serviceauthorization ''dTYPkfosjJ6dMSBZNAPff''"}'
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Type:
- application/json
Date:
- Wed, 15 Jun 2022 12:43:18 GMT
- Thu, 16 Jun 2022 14:54:33 GMT
Fastly-Ratelimit-Remaining:
- "974"
- "956"
Fastly-Ratelimit-Reset:
- "1655298000"
- "1655391600"
Status:
- 204 No Content
- 404 Not Found
Strict-Transport-Security:
- max-age=31536000
Vary:
- Accept-Encoding
Via:
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9037-CONTROL-SLWDC, cache-bma1665-BMA
- cache-control-slwdc9035-CONTROL-SLWDC, cache-bma1646-BMA
X-Timer:
- S1655296998.615067,VS0,VE438
status: 204 No Content
code: 204
- S1655391273.306991,VS0,VE433
status: 404 Not Found
code: 404
duration: ""
19 changes: 10 additions & 9 deletions fastly/fixtures/service_authorizations/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
version: 1
interactions:
- request:
body: '{"data":{"attributes":{"permission":"full"},"relationships":{"service":{"data":{"id":"7ZVxm5pPWdzKdl3P5UW7jR","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}},"type":"service_authorization"}}'
body: |
{"data":{"type":"service_authorization","attributes":{"permission":"full"},"relationships":{"service":{"data":{"type":"service","id":"7i6HN3TK9wS159v2gPAZ8A"}},"user":{"data":{"type":"user","id":"4tKBSuFhNEiIpNDxmmVydt"}}}},"included":[{"type":"user","id":"4tKBSuFhNEiIpNDxmmVydt"},{"type":"service","id":"7i6HN3TK9wS159v2gPAZ8A"}]}
form: {}
headers:
Accept:
- application/json
- application/vnd.api+json
Content-Type:
- application/json
- application/vnd.api+json
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations
method: POST
response:
body: '{"data":{"id":"RpPAg3cWoOTz6WbzXkA2a","type":"service_authorization","attributes":{"created_at":"2022-06-15T12:43:16Z","updated_at":"2022-06-15T12:43:16Z","deleted_at":null,"permission":"full"},"relationships":{"service":{"data":{"id":"7ZVxm5pPWdzKdl3P5UW7jR","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
body: '{"data":{"id":"dTYPkfosjJ6dMSBZNAPff","type":"service_authorization","attributes":{"created_at":"2022-06-16T14:54:32Z","updated_at":"2022-06-16T14:54:32Z","deleted_at":null,"permission":"full"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -23,11 +24,11 @@ interactions:
Content-Type:
- application/vnd.api+json
Date:
- Wed, 15 Jun 2022 12:43:16 GMT
- Thu, 16 Jun 2022 14:54:32 GMT
Fastly-Ratelimit-Remaining:
- "976"
- "959"
Fastly-Ratelimit-Reset:
- "1655298000"
- "1655391600"
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -41,9 +42,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1665-BMA
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
X-Timer:
- S1655296997.569927,VS0,VE263
- S1655391272.193824,VS0,VE172
status: 200 OK
code: 200
duration: ""
24 changes: 10 additions & 14 deletions fastly/fixtures/service_authorizations/delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,35 @@ interactions:
headers:
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/RpPAg3cWoOTz6WbzXkA2a
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
method: DELETE
response:
body: '{"msg":"Record not found","detail":"Cannot find serviceauthorization ''RpPAg3cWoOTz6WbzXkA2a''"}'
body: ""
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Type:
- application/json
Date:
- Wed, 15 Jun 2022 13:15:35 GMT
- Thu, 16 Jun 2022 14:54:33 GMT
Fastly-Ratelimit-Remaining:
- "995"
- "957"
Fastly-Ratelimit-Reset:
- "1655301600"
- "1655391600"
Status:
- 404 Not Found
- 204 No Content
Strict-Transport-Security:
- max-age=31536000
Vary:
- Accept-Encoding
Via:
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9037-CONTROL-SLWDC, cache-bma1653-BMA
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
X-Timer:
- S1655298935.038067,VS0,VE340
status: 404 Not Found
code: 404
- S1655391273.032612,VS0,VE260
status: 204 No Content
code: 204
duration: ""
10 changes: 5 additions & 5 deletions fastly/fixtures/service_authorizations/get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ interactions:
headers:
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/RpPAg3cWoOTz6WbzXkA2a
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
method: GET
response:
body: '{"data":{"id":"RpPAg3cWoOTz6WbzXkA2a","type":"service_authorization","attributes":{"created_at":"2022-06-15T12:43:16Z","updated_at":"2022-06-15T12:43:16Z","deleted_at":null,"permission":"full"},"relationships":{"service":{"data":{"id":"7ZVxm5pPWdzKdl3P5UW7jR","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
body: '{"data":{"id":"dTYPkfosjJ6dMSBZNAPff","type":"service_authorization","attributes":{"created_at":"2022-06-16T14:54:32Z","updated_at":"2022-06-16T14:54:32Z","deleted_at":null,"permission":"full"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -19,7 +19,7 @@ interactions:
Content-Type:
- application/vnd.api+json
Date:
- Wed, 15 Jun 2022 12:43:17 GMT
- Thu, 16 Jun 2022 14:54:32 GMT
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -33,9 +33,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1665-BMA
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
X-Timer:
- S1655296997.874631,VS0,VE326
- S1655391272.387855,VS0,VE432
status: 200 OK
code: 200
duration: ""
21 changes: 11 additions & 10 deletions fastly/fixtures/service_authorizations/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
version: 1
interactions:
- request:
body: '{"data":{"id":"RpPAg3cWoOTz6WbzXkA2a","attributes":{"permission":"purge_select"},"type":"service_authorization"}}'
body: |
{"data":{"type":"service_authorization","id":"dTYPkfosjJ6dMSBZNAPff","attributes":{"permission":"purge_select"}}}
form: {}
headers:
Accept:
- application/json
- application/vnd.api+json
Content-Type:
- application/json
- application/vnd.api+json
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/RpPAg3cWoOTz6WbzXkA2a
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
method: PATCH
response:
body: '{"data":{"id":"RpPAg3cWoOTz6WbzXkA2a","type":"service_authorization","attributes":{"created_at":"2022-06-15T12:43:16Z","updated_at":"2022-06-15T12:43:17Z","deleted_at":null,"permission":"purge_select"},"relationships":{"service":{"data":{"id":"7ZVxm5pPWdzKdl3P5UW7jR","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
body: '{"data":{"id":"dTYPkfosjJ6dMSBZNAPff","type":"service_authorization","attributes":{"created_at":"2022-06-16T14:54:32Z","updated_at":"2022-06-16T14:54:32Z","deleted_at":null,"permission":"purge_select"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -23,11 +24,11 @@ interactions:
Content-Type:
- application/vnd.api+json
Date:
- Wed, 15 Jun 2022 12:43:17 GMT
- Thu, 16 Jun 2022 14:54:33 GMT
Fastly-Ratelimit-Remaining:
- "975"
- "958"
Fastly-Ratelimit-Reset:
- "1655298000"
- "1655391600"
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -41,9 +42,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9035-CONTROL-SLWDC, cache-bma1665-BMA
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
X-Timer:
- S1655296997.218665,VS0,VE383
- S1655391273.836430,VS0,VE181
status: 200 OK
code: 200
duration: ""
28 changes: 14 additions & 14 deletions fastly/service_authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestClient_ServiceAuthorizations(t *testing.T) {
var sa *ServiceAuthorization
record(t, fixtureBase+"create", func(c *Client) {
sa, err = c.CreateServiceAuthorization(&CreateServiceAuthorizationInput{
ServiceID: "7ZVxm5pPWdzKdl3P5UW7jR",
UserID: "4tKBSuFhNEiIpNDxmmVydt",
Service: &SAService{ID: testServiceID},
User: &SAUser{ID: testUserID},
Permission: "full",
})
})
Expand All @@ -33,12 +33,12 @@ func TestClient_ServiceAuthorizations(t *testing.T) {
})
}()

if sa.ServiceID != "7ZVxm5pPWdzKdl3P5UW7jR" {
t.Errorf("bad service id: %v", sa.ServiceID)
if sa.Service.ID != testServiceID {
t.Errorf("bad service id: %v", sa.Service.ID)
}

if sa.UserID != "4tKBSuFhNEiIpNDxmmVydt" {
t.Errorf("bad user id: %v", sa.UserID)
if sa.User.ID != testUserID {
t.Errorf("bad user id: %v", sa.User.ID)
}

if sa.Permission != "full" {
Expand All @@ -56,8 +56,8 @@ func TestClient_ServiceAuthorizations(t *testing.T) {
t.Fatal(err)
}

if nsa.ServiceID != "7ZVxm5pPWdzKdl3P5UW7jR" {
t.Errorf("bad service id: %v", nsa.ServiceID)
if nsa.Service.ID != testServiceID {
t.Errorf("bad service id: %v", nsa.Service)
}

// Update
Expand All @@ -72,8 +72,8 @@ func TestClient_ServiceAuthorizations(t *testing.T) {
t.Fatal(err)
}

if usa.ServiceID != "7ZVxm5pPWdzKdl3P5UW7jR" {
t.Errorf("bad service id: %v", usa.ServiceID)
if usa.Service.ID != testServiceID {
t.Errorf("bad service id: %v", usa.Service)
}
if usa.Permission != "purge_select" {
t.Errorf("bad permission: %v", usa.Permission)
Expand Down Expand Up @@ -103,16 +103,16 @@ func TestClient_GetServiceAuthorization_validation(t *testing.T) {
func TestClient_CreateServiceAuthorization_validation(t *testing.T) {
var err error
_, err = testClient.CreateServiceAuthorization(&CreateServiceAuthorizationInput{
ServiceID: "",
UserID: "",
Service: &SAService{ID: ""},
User: &SAUser{ID: ""},
})
if err != ErrMissingServiceID {
t.Errorf("bad error: %s", err)
}

_, err = testClient.CreateServiceAuthorization(&CreateServiceAuthorizationInput{
ServiceID: "my-service-id",
UserID: "",
Service: &SAService{ID: "my-service-id"},
User: &SAUser{ID: ""},
})
if err != ErrMissingUserID {
t.Errorf("bad error: %s", err)
Expand Down
11 changes: 11 additions & 0 deletions scripts/fixFixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@ set -e

FASTLY_TEST_SERVICE_ID=$1
DEFAULT_TEST_SERVICE_ID="7i6HN3TK9wS159v2gPAZ8A"
DEFAULT_TEST_USER_ID="4tKBSuFhNEiIpNDxmmVydt"
FIXTURESDIR="$(pwd)/fastly/fixtures/"

if [[ -z ${FASTLY_TEST_SERVICE_ID} && -z $1 ]]; then
echo "You must supply a service ID as the first argument"
exit
fi

if [[ -z ${FASTLY_TEST_USER_ID} && -z $2 ]]; then
echo "You must supply a user ID as the second argument"
exit
fi

for file in $(grep --recursive --files-with-matches "${FASTLY_TEST_SERVICE_ID}" "${FIXTURESDIR}")
do
sed -i.bak "s/${FASTLY_TEST_SERVICE_ID}/${DEFAULT_TEST_SERVICE_ID}/g" "$file" && rm "${file}.bak"
done

for file in $(grep --recursive --files-with-matches "${FASTLY_TEST_USER_ID}" "${FIXTURESDIR}")
do
sed -i.bak "s/${FASTLY_TEST_USER_ID}/${DEFAULT_TEST_USER_ID}/g" "$file" && rm "${file}.bak"
done

0 comments on commit e172702

Please sign in to comment.