Skip to content

Commit 4338a20

Browse files
committed
script fix to run against server
1 parent c4883f4 commit 4338a20

File tree

3 files changed

+839
-1677
lines changed

3 files changed

+839
-1677
lines changed

tests/api-spec-validation/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ help:
1212
# Build the validator
1313
build:
1414
@echo "Building API spec validator..."
15-
go mod vendor
1615
go build -o bin/validator cmd/validator/main.go
1716
go build -o bin/live-test cmd/live-test/main.go
1817

@@ -44,7 +43,7 @@ test-live: build
4443
--server=https://devtron-ent-2.devtron.info \
4544
--specs=../../specs \
4645
--output=./reports \
47-
--token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IkFQSS1UT0tFTjphZG1pbiIsInZlcnNpb24iOiIxIiwiaXNzIjoiYXBpVG9rZW5Jc3N1ZXIiLCJleHAiOjE3NTY1NTc1NzR9.ZHhQdhXpGygCOiO7rDah0mBB7zZYZ3y9WlJL9egRfq4 \
46+
--token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTQzOTM3MzQsImp0aSI6ImRiODUxYzg5LTg0YjUtNDhiOS1hYTcyLWQ0ZTA0MjRjN2U4MSIsImlhdCI6MTc1NDMwNzMzNCwiaXNzIjoiYXJnb2NkIiwibmJmIjoxNzU0MzA3MzM0LCJzdWIiOiJhZG1pbiJ9.wYGmONdpNUEjtAxXz_mViW44Rxh0YU3dax_SEuoAH5c \
4847
--verbose
4948

5049
# Compare specs with REST handlers

tests/api-spec-validation/framework.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,35 @@ func NewAPISpecValidator(serverURL string, logger *zap.SugaredLogger) *APISpecVa
6262
}
6363
}
6464

65+
func (v *APISpecValidator) buildCurlCommand(req *http.Request) string {
66+
var cmd strings.Builder
67+
68+
cmd.WriteString("curl --location '")
69+
cmd.WriteString(req.URL.String())
70+
cmd.WriteString("' \\\n")
71+
72+
// Add headers
73+
for key, values := range req.Header {
74+
for _, value := range values {
75+
cmd.WriteString(fmt.Sprintf(" --header '%s: %s' \\\n", key, value))
76+
}
77+
}
78+
79+
// Add cookies
80+
if len(v.additionalCookies) > 0 {
81+
cmd.WriteString(" --cookie '")
82+
for name, value := range v.additionalCookies {
83+
cmd.WriteString(name)
84+
cmd.WriteString("=")
85+
cmd.WriteString(value)
86+
cmd.WriteString("; ")
87+
}
88+
cmd.WriteString("' \\\n")
89+
}
90+
91+
return cmd.String()
92+
}
93+
6594
// LoadSpecs loads all OpenAPI specs from the specs directory
6695
func (v *APISpecValidator) LoadSpecs(specsDir string) error {
6796
v.logger.Infow("Loading API specs from directory", "dir", specsDir)
@@ -215,14 +244,6 @@ func (v *APISpecValidator) testEndpoint(result *ValidationResult, path, method s
215244
req.Header.Set("Content-Type", "application/json")
216245
req.Header.Set("Accept", "*/*")
217246
req.Header.Set("Accept-Language", "en-US,en;q=0.9,hi;q=0.8")
218-
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36")
219-
req.Header.Set("Sec-Ch-Ua", `"Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138"`)
220-
req.Header.Set("Sec-Ch-Ua-Mobile", "?0")
221-
req.Header.Set("Sec-Ch-Ua-Platform", `"macOS"`)
222-
req.Header.Set("Sec-Fetch-Dest", "empty")
223-
req.Header.Set("Sec-Fetch-Mode", "cors")
224-
req.Header.Set("Sec-Fetch-Site", "same-origin")
225-
req.Header.Set("Priority", "u=1, i")
226247

227248
// Set authentication - cookie-based only as per curl request pattern
228249
v.setAuthentication(req)
@@ -237,6 +258,9 @@ func (v *APISpecValidator) testEndpoint(result *ValidationResult, path, method s
237258
}
238259
}
239260

261+
// print the curl command for debugging
262+
v.logger.Debugw("Curl command", "command", v.buildCurlCommand(req))
263+
240264
// Make the request
241265
resp, err := v.httpClient.Do(req)
242266
if err != nil {

0 commit comments

Comments
 (0)