Skip to content

Commit be8a5d4

Browse files
Fix Test: The obove test sets the status to available so in the next test the expected value should be available
1 parent d58ad9c commit be8a5d4

File tree

8 files changed

+719
-23
lines changed

8 files changed

+719
-23
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.0-SNAPSHOT
1+
2.4.0-SNAPSHOT

samples/client/petstore-security-test/go/README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge
1111

1212
## Installation
1313
Put the package under your project folder and add the following in import:
14-
```
15-
"./swagger"
14+
```golang
15+
import "./swagger"
1616
```
1717

1818
## Documentation for API Endpoints
@@ -35,12 +35,12 @@ Class | Method | HTTP request | Description
3535
- **Type**: API key
3636

3737
Example
38-
```
39-
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
40-
Key: "APIKEY",
41-
Prefix: "Bearer", // Omit if not necessary.
42-
})
43-
r, err := client.Service.Operation(auth, args)
38+
```golang
39+
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
40+
Key: "APIKEY",
41+
Prefix: "Bearer", // Omit if not necessary.
42+
})
43+
r, err := client.Service.Operation(auth, args)
4444
```
4545
## petstore_auth
4646
- **Type**: OAuth
@@ -51,20 +51,20 @@ Example
5151
- **read:pets**: read your pets *_/ ' \" =end -- \\r\\n \\n \\r
5252

5353
Example
54-
```
55-
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
56-
r, err := client.Service.Operation(auth, args)
54+
```golang
55+
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
56+
r, err := client.Service.Operation(auth, args)
5757
```
5858

5959
Or via OAuth2 module to automatically refresh tokens and perform user authentication.
60-
```
61-
import "golang.org/x/oauth2"
60+
```golang
61+
import "golang.org/x/oauth2"
6262

63-
/ .. Perform OAuth2 round trip request and obtain a token .. //
63+
/* Perform OAuth2 round trip request and obtain a token */
6464

65-
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
66-
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource)
67-
r, err := client.Service.Operation(auth, args)
65+
tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
66+
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource)
67+
r, err := client.Service.Operation(auth, args)
6868
```
6969

7070
## Author
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
swagger: "2.0"
3+
info:
4+
description: "This spec is mainly for testing Petstore server and contains fake\
5+
\ endpoints, models. Please do not use this for any other purpose. Special characters:\
6+
\ \" \\ */ ' \" =end -- \r\n \n \r"
7+
version: "1.0.0 */ ' \" =end -- \\r\\n \\n \\r"
8+
title: "Swagger Petstore */ ' \" =end -- \\r\\n \\n \\r"
9+
termsOfService: "http://swagger.io/terms/ */ ' \" =end -- \\r\\n \\n \\r"
10+
contact:
11+
email: "[email protected] */ ' \" =end -- \\r\\n \\n \\r"
12+
license:
13+
name: "Apache-2.0 */ ' \" =end -- \\r\\n \\n \\r"
14+
url: "http://www.apache.org/licenses/LICENSE-2.0.html */ ' \" =end -- \\r\\n \\\
15+
n \\r"
16+
host: "petstore.swagger.io */ ' \" =end -- \\r\\n \\n \\r"
17+
basePath: "/v2 */ ' \" =end -- \\r\\n \\n \\r"
18+
tags:
19+
- name: "fake"
20+
description: "Everything about your Pets */ ' \" =end -- \\r\\n \\n \\r"
21+
externalDocs:
22+
description: "Find out more */ ' \" =end -- \\r\\n \\n \\r"
23+
url: "http://swagger.io"
24+
paths:
25+
/fake:
26+
put:
27+
tags:
28+
- "fake"
29+
summary: "To test code injection */ ' \" =end -- \\r\\n \\n \\r"
30+
operationId: "testCodeInject */ ' \" =end -- \\r\\n \\n \\r"
31+
consumes:
32+
- "application/json"
33+
- "*/ ' \" =end -- \r\n \n \r"
34+
produces:
35+
- "application/json"
36+
- "*/ ' \" =end -- \r\n \n \r"
37+
parameters:
38+
- name: "test code inject */ ' \" =end -- \\r\\n \\n \\r"
39+
in: "formData"
40+
description: "To test code injection */ ' \" =end -- \\r\\n \\n \\r"
41+
required: false
42+
type: "string"
43+
x-exportParamName: "TestCodeInjectEndRnNR"
44+
x-optionalDataType: "String"
45+
responses:
46+
400:
47+
description: "To test code injection */ ' \" =end -- \\r\\n \\n \\r"
48+
securityDefinitions:
49+
petstore_auth:
50+
type: "oauth2"
51+
authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog"
52+
flow: "implicit"
53+
scopes:
54+
write:pets: "modify pets in your account */ ' \" =end -- \\r\\n \\n \\r"
55+
read:pets: "read your pets */ ' \" =end -- \\r\\n \\n \\r"
56+
api_key:
57+
type: "apiKey"
58+
name: "api_key */ ' \" =end -- \\r\\n \\n \\r"
59+
in: "header"
60+
definitions:
61+
Return:
62+
properties:
63+
return:
64+
type: "integer"
65+
format: "int32"
66+
description: "property description */ ' \" =end -- \\r\\n \\n \\r"
67+
xml:
68+
name: "Return"
69+
description: "Model for testing reserved words */ ' \" =end -- \\r\\n \\n \\r"
70+
externalDocs:
71+
description: "Find out more about Swagger */ ' \" =end -- \\r\\n \\n \\r"
72+
url: "http://swagger.io"
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
3+
*
4+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
5+
*
6+
* API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
7+
* Contact: [email protected] *_/ ' \" =end -- \\r\\n \\n \\r
8+
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
9+
*/
10+
11+
package swagger
12+
13+
import (
14+
"context"
15+
"io/ioutil"
16+
"net/http"
17+
"net/url"
18+
"strings"
19+
"github.com/antihax/optional"
20+
)
21+
22+
// Linger please
23+
var (
24+
_ context.Context
25+
)
26+
27+
type FakeApiService service
28+
29+
/*
30+
FakeApiService To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
31+
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
32+
* @param optional nil or *TestCodeInjectEndRnNROpts - Optional Parameters:
33+
* @param "TestCodeInjectEndRnNR" (optional.String) - To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
34+
35+
36+
*/
37+
38+
type TestCodeInjectEndRnNROpts struct {
39+
TestCodeInjectEndRnNR optional.String
40+
}
41+
42+
func (a *FakeApiService) TestCodeInjectEndRnNR(ctx context.Context, localVarOptionals *TestCodeInjectEndRnNROpts) (*http.Response, error) {
43+
var (
44+
localVarHttpMethod = strings.ToUpper("Put")
45+
localVarPostBody interface{}
46+
localVarFileName string
47+
localVarFileBytes []byte
48+
49+
)
50+
51+
// create path and map variables
52+
localVarPath := a.client.cfg.BasePath + "/fake"
53+
54+
localVarHeaderParams := make(map[string]string)
55+
localVarQueryParams := url.Values{}
56+
localVarFormParams := url.Values{}
57+
58+
// to determine the Content-Type header
59+
localVarHttpContentTypes := []string{"application/json", "*_/ ' =end -- "}
60+
61+
// set Content-Type header
62+
localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
63+
if localVarHttpContentType != "" {
64+
localVarHeaderParams["Content-Type"] = localVarHttpContentType
65+
}
66+
67+
// to determine the Accept header
68+
localVarHttpHeaderAccepts := []string{"application/json", "*_/ ' =end -- "}
69+
70+
// set Accept header
71+
localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
72+
if localVarHttpHeaderAccept != "" {
73+
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
74+
}
75+
if localVarOptionals != nil && localVarOptionals.TestCodeInjectEndRnNR.IsSet() {
76+
localVarFormParams.Add("test code inject */ ' " =end -- \r\n \n \r", parameterToString(localVarOptionals.TestCodeInjectEndRnNR.Value(), ""))
77+
}
78+
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
79+
if err != nil {
80+
return nil, err
81+
}
82+
83+
localVarHttpResponse, err := a.client.callAPI(r)
84+
if err != nil || localVarHttpResponse == nil {
85+
return localVarHttpResponse, err
86+
}
87+
88+
localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
89+
localVarHttpResponse.Body.Close()
90+
if err != nil {
91+
return localVarHttpResponse, err
92+
}
93+
94+
95+
if localVarHttpResponse.StatusCode >= 300 {
96+
newErr := GenericSwaggerError{
97+
body: localVarBody,
98+
error: localVarHttpResponse.Status,
99+
}
100+
101+
return localVarHttpResponse, newErr
102+
}
103+
104+
return localVarHttpResponse, nil
105+
}

0 commit comments

Comments
 (0)