Add tests for http basic authentication in python client (#16488)

* add tests for http basic auth in python client

* add new files
This commit is contained in:
William Cheng
2023-09-03 19:11:53 +08:00
committed by GitHub
parent b59719a6ea
commit 47a85e880b
41 changed files with 2096 additions and 30 deletions

View File

@@ -3,6 +3,7 @@ Org.OpenAPITools.sln
README.md
api/openapi.yaml
appveyor.yml
docs/AuthApi.md
docs/Bird.md
docs/BodyApi.md
docs/Category.md
@@ -21,6 +22,7 @@ docs/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.md
docs/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.md
git_push.sh
src/Org.OpenAPITools.Test/Org.OpenAPITools.Test.csproj
src/Org.OpenAPITools/Api/AuthApi.cs
src/Org.OpenAPITools/Api/BodyApi.cs
src/Org.OpenAPITools/Api/FormApi.cs
src/Org.OpenAPITools/Api/HeaderApi.cs

View File

@@ -85,17 +85,21 @@ namespace Example
Configuration config = new Configuration();
config.BasePath = "http://localhost:3000";
var apiInstance = new BodyApi(config);
// Configure HTTP basic authorization: http_auth
config.Username = "YOUR_USERNAME";
config.Password = "YOUR_PASSWORD";
var apiInstance = new AuthApi(config);
try
{
// Test binary (gif) response body
System.IO.Stream result = apiInstance.TestBinaryGif();
// To test HTTP basic authentication
string result = apiInstance.TestAuthHttpBasic();
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling BodyApi.TestBinaryGif: " + e.Message );
Debug.Print("Exception when calling AuthApi.TestAuthHttpBasic: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
@@ -112,6 +116,7 @@ All URIs are relative to *http://localhost:3000*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AuthApi* | [**TestAuthHttpBasic**](docs/AuthApi.md#testauthhttpbasic) | **POST** /auth/http/basic | To test HTTP basic authentication
*BodyApi* | [**TestBinaryGif**](docs/BodyApi.md#testbinarygif) | **POST** /binary/gif | Test binary (gif) response body
*BodyApi* | [**TestBodyApplicationOctetstreamBinary**](docs/BodyApi.md#testbodyapplicationoctetstreambinary) | **POST** /body/application/octetstream/binary | Test body parameter(s)
*BodyApi* | [**TestBodyMultipartFormdataArrayOfBinary**](docs/BodyApi.md#testbodymultipartformdataarrayofbinary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime
@@ -152,5 +157,10 @@ Class | Method | HTTP request | Description
<a id="documentation-for-authorization"></a>
## Documentation for Authorization
Endpoints do not require authorization.
Authentication schemes defined for the API:
<a id="http_auth"></a>
### http_auth
- **Type**: HTTP basic authentication

View File

@@ -442,6 +442,22 @@ paths:
summary: Test array of binary in multipart mime
tags:
- body
/auth/http/basic:
post:
description: To test HTTP basic authentication
operationId: test/auth/http/basic
responses:
"200":
content:
text/plain:
schema:
type: string
description: Successful operation
security:
- http_auth: []
summary: To test HTTP basic authentication
tags:
- auth
components:
requestBodies:
Pet:
@@ -702,4 +718,8 @@ components:
required:
- files
type: object
securitySchemes:
http_auth:
scheme: basic
type: http

View File

@@ -0,0 +1,98 @@
# Org.OpenAPITools.Api.AuthApi
All URIs are relative to *http://localhost:3000*
| Method | HTTP request | Description |
|--------|--------------|-------------|
| [**TestAuthHttpBasic**](AuthApi.md#testauthhttpbasic) | **POST** /auth/http/basic | To test HTTP basic authentication |
<a id="testauthhttpbasic"></a>
# **TestAuthHttpBasic**
> string TestAuthHttpBasic ()
To test HTTP basic authentication
To test HTTP basic authentication
### Example
```csharp
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;
namespace Example
{
public class TestAuthHttpBasicExample
{
public static void Main()
{
Configuration config = new Configuration();
config.BasePath = "http://localhost:3000";
// Configure HTTP basic authorization: http_auth
config.Username = "YOUR_USERNAME";
config.Password = "YOUR_PASSWORD";
var apiInstance = new AuthApi(config);
try
{
// To test HTTP basic authentication
string result = apiInstance.TestAuthHttpBasic();
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling AuthApi.TestAuthHttpBasic: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
```
#### Using the TestAuthHttpBasicWithHttpInfo variant
This returns an ApiResponse object which contains the response data, status code and headers.
```csharp
try
{
// To test HTTP basic authentication
ApiResponse<string> response = apiInstance.TestAuthHttpBasicWithHttpInfo();
Debug.Write("Status Code: " + response.StatusCode);
Debug.Write("Response Headers: " + response.Headers);
Debug.Write("Response Body: " + response.Data);
}
catch (ApiException e)
{
Debug.Print("Exception when calling AuthApi.TestAuthHttpBasicWithHttpInfo: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
```
### Parameters
This endpoint does not need any parameter.
### Return type
**string**
### Authorization
[http_auth](../README.md#http_auth)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

View File

@@ -0,0 +1,67 @@
/*
* Echo Server API
*
* Echo Server API
*
* The version of the OpenAPI document: 0.1.0
* Contact: team@openapitools.org
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
using System;
using System.IO;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using RestSharp;
using Xunit;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Api;
namespace Org.OpenAPITools.Test.Api
{
/// <summary>
/// Class for testing AuthApi
/// </summary>
/// <remarks>
/// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech).
/// Please update the test case below to test the API endpoint.
/// </remarks>
public class AuthApiTests : IDisposable
{
private AuthApi instance;
public AuthApiTests()
{
instance = new AuthApi();
}
public void Dispose()
{
// Cleanup when everything is done.
}
/// <summary>
/// Test an instance of AuthApi
/// </summary>
[Fact]
public void InstanceTest()
{
// TODO uncomment below to test 'IsType' AuthApi
//Assert.IsType<AuthApi>(instance);
}
/// <summary>
/// Test TestAuthHttpBasic
/// </summary>
[Fact]
public void TestAuthHttpBasicTest()
{
// TODO uncomment below to test the method and replace null with proper value
//var response = instance.TestAuthHttpBasic();
//Assert.IsType<string>(response);
}
}
}

View File

@@ -0,0 +1,341 @@
/*
* Echo Server API
*
* Echo Server API
*
* The version of the OpenAPI document: 0.1.0
* Contact: team@openapitools.org
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Net.Mime;
using Org.OpenAPITools.Client;
namespace Org.OpenAPITools.Api
{
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public interface IAuthApiSync : IApiAccessor
{
#region Synchronous Operations
/// <summary>
/// To test HTTP basic authentication
/// </summary>
/// <remarks>
/// To test HTTP basic authentication
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>string</returns>
string TestAuthHttpBasic(int operationIndex = 0);
/// <summary>
/// To test HTTP basic authentication
/// </summary>
/// <remarks>
/// To test HTTP basic authentication
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>ApiResponse of string</returns>
ApiResponse<string> TestAuthHttpBasicWithHttpInfo(int operationIndex = 0);
#endregion Synchronous Operations
}
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public interface IAuthApiAsync : IApiAccessor
{
#region Asynchronous Operations
/// <summary>
/// To test HTTP basic authentication
/// </summary>
/// <remarks>
/// To test HTTP basic authentication
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of string</returns>
System.Threading.Tasks.Task<string> TestAuthHttpBasicAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
/// <summary>
/// To test HTTP basic authentication
/// </summary>
/// <remarks>
/// To test HTTP basic authentication
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ApiResponse (string)</returns>
System.Threading.Tasks.Task<ApiResponse<string>> TestAuthHttpBasicWithHttpInfoAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
#endregion Asynchronous Operations
}
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public interface IAuthApi : IAuthApiSync, IAuthApiAsync
{
}
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
public partial class AuthApi : IAuthApi
{
private Org.OpenAPITools.Client.ExceptionFactory _exceptionFactory = (name, response) => null;
/// <summary>
/// Initializes a new instance of the <see cref="AuthApi"/> class.
/// </summary>
/// <returns></returns>
public AuthApi() : this((string)null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="AuthApi"/> class.
/// </summary>
/// <returns></returns>
public AuthApi(string basePath)
{
this.Configuration = Org.OpenAPITools.Client.Configuration.MergeConfigurations(
Org.OpenAPITools.Client.GlobalConfiguration.Instance,
new Org.OpenAPITools.Client.Configuration { BasePath = basePath }
);
this.Client = new Org.OpenAPITools.Client.ApiClient(this.Configuration.BasePath);
this.AsynchronousClient = new Org.OpenAPITools.Client.ApiClient(this.Configuration.BasePath);
this.ExceptionFactory = Org.OpenAPITools.Client.Configuration.DefaultExceptionFactory;
}
/// <summary>
/// Initializes a new instance of the <see cref="AuthApi"/> class
/// using Configuration object
/// </summary>
/// <param name="configuration">An instance of Configuration</param>
/// <returns></returns>
public AuthApi(Org.OpenAPITools.Client.Configuration configuration)
{
if (configuration == null) throw new ArgumentNullException("configuration");
this.Configuration = Org.OpenAPITools.Client.Configuration.MergeConfigurations(
Org.OpenAPITools.Client.GlobalConfiguration.Instance,
configuration
);
this.Client = new Org.OpenAPITools.Client.ApiClient(this.Configuration.BasePath);
this.AsynchronousClient = new Org.OpenAPITools.Client.ApiClient(this.Configuration.BasePath);
ExceptionFactory = Org.OpenAPITools.Client.Configuration.DefaultExceptionFactory;
}
/// <summary>
/// Initializes a new instance of the <see cref="AuthApi"/> class
/// using a Configuration object and client instance.
/// </summary>
/// <param name="client">The client interface for synchronous API access.</param>
/// <param name="asyncClient">The client interface for asynchronous API access.</param>
/// <param name="configuration">The configuration object.</param>
public AuthApi(Org.OpenAPITools.Client.ISynchronousClient client, Org.OpenAPITools.Client.IAsynchronousClient asyncClient, Org.OpenAPITools.Client.IReadableConfiguration configuration)
{
if (client == null) throw new ArgumentNullException("client");
if (asyncClient == null) throw new ArgumentNullException("asyncClient");
if (configuration == null) throw new ArgumentNullException("configuration");
this.Client = client;
this.AsynchronousClient = asyncClient;
this.Configuration = configuration;
this.ExceptionFactory = Org.OpenAPITools.Client.Configuration.DefaultExceptionFactory;
}
/// <summary>
/// The client for accessing this underlying API asynchronously.
/// </summary>
public Org.OpenAPITools.Client.IAsynchronousClient AsynchronousClient { get; set; }
/// <summary>
/// The client for accessing this underlying API synchronously.
/// </summary>
public Org.OpenAPITools.Client.ISynchronousClient Client { get; set; }
/// <summary>
/// Gets the base path of the API client.
/// </summary>
/// <value>The base path</value>
public string GetBasePath()
{
return this.Configuration.BasePath;
}
/// <summary>
/// Gets or sets the configuration object
/// </summary>
/// <value>An instance of the Configuration</value>
public Org.OpenAPITools.Client.IReadableConfiguration Configuration { get; set; }
/// <summary>
/// Provides a factory method hook for the creation of exceptions.
/// </summary>
public Org.OpenAPITools.Client.ExceptionFactory ExceptionFactory
{
get
{
if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1)
{
throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported.");
}
return _exceptionFactory;
}
set { _exceptionFactory = value; }
}
/// <summary>
/// To test HTTP basic authentication To test HTTP basic authentication
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>string</returns>
public string TestAuthHttpBasic(int operationIndex = 0)
{
Org.OpenAPITools.Client.ApiResponse<string> localVarResponse = TestAuthHttpBasicWithHttpInfo();
return localVarResponse.Data;
}
/// <summary>
/// To test HTTP basic authentication To test HTTP basic authentication
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>ApiResponse of string</returns>
public Org.OpenAPITools.Client.ApiResponse<string> TestAuthHttpBasicWithHttpInfo(int operationIndex = 0)
{
Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();
string[] _contentTypes = new string[] {
};
// to determine the Accept header
string[] _accepts = new string[] {
"text/plain"
};
var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
if (localVarContentType != null)
{
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
}
var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts);
if (localVarAccept != null)
{
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
}
localVarRequestOptions.Operation = "AuthApi.TestAuthHttpBasic";
localVarRequestOptions.OperationIndex = operationIndex;
// authentication (http_auth) required
// http basic authentication required
if (!string.IsNullOrEmpty(this.Configuration.Username) || !string.IsNullOrEmpty(this.Configuration.Password) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization"))
{
localVarRequestOptions.HeaderParameters.Add("Authorization", "Basic " + Org.OpenAPITools.Client.ClientUtils.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password));
}
// make the HTTP request
var localVarResponse = this.Client.Post<string>("/auth/http/basic", localVarRequestOptions, this.Configuration);
if (this.ExceptionFactory != null)
{
Exception _exception = this.ExceptionFactory("TestAuthHttpBasic", localVarResponse);
if (_exception != null)
{
throw _exception;
}
}
return localVarResponse;
}
/// <summary>
/// To test HTTP basic authentication To test HTTP basic authentication
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of string</returns>
public async System.Threading.Tasks.Task<string> TestAuthHttpBasicAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
Org.OpenAPITools.Client.ApiResponse<string> localVarResponse = await TestAuthHttpBasicWithHttpInfoAsync(operationIndex, cancellationToken).ConfigureAwait(false);
return localVarResponse.Data;
}
/// <summary>
/// To test HTTP basic authentication To test HTTP basic authentication
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ApiResponse (string)</returns>
public async System.Threading.Tasks.Task<Org.OpenAPITools.Client.ApiResponse<string>> TestAuthHttpBasicWithHttpInfoAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();
string[] _contentTypes = new string[] {
};
// to determine the Accept header
string[] _accepts = new string[] {
"text/plain"
};
var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
if (localVarContentType != null)
{
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
}
var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts);
if (localVarAccept != null)
{
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
}
localVarRequestOptions.Operation = "AuthApi.TestAuthHttpBasic";
localVarRequestOptions.OperationIndex = operationIndex;
// authentication (http_auth) required
// http basic authentication required
if (!string.IsNullOrEmpty(this.Configuration.Username) || !string.IsNullOrEmpty(this.Configuration.Password) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization"))
{
localVarRequestOptions.HeaderParameters.Add("Authorization", "Basic " + Org.OpenAPITools.Client.ClientUtils.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password));
}
// make the HTTP request
var localVarResponse = await this.AsynchronousClient.PostAsync<string>("/auth/http/basic", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false);
if (this.ExceptionFactory != null)
{
Exception _exception = this.ExceptionFactory("TestAuthHttpBasic", localVarResponse);
if (_exception != null)
{
throw _exception;
}
}
return localVarResponse;
}
}
}