forked from loafle/openapi-generator-original
Add test cases for API key and HTTP basic auth
This commit is contained in:
parent
f616605e7e
commit
16ba2a54ea
@ -0,0 +1,40 @@
|
||||
package io.swagger.client.auth;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.*;
|
||||
|
||||
public class ApiKeyAuthTest {
|
||||
@Test
|
||||
public void testProcessParamsInQuery() {
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
ApiKeyAuth auth = new ApiKeyAuth("query", "api_key");
|
||||
auth.setApiKey("my-api-key");
|
||||
auth.processParams(queryParams, headerParams);
|
||||
|
||||
assertEquals(1, queryParams.size());
|
||||
assertEquals("my-api-key", queryParams.get("api_key"));
|
||||
// no changes to header parameters
|
||||
assertEquals(0, headerParams.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessParamsInHeaderWithPrefix() {
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN");
|
||||
auth.setApiKey("my-api-token");
|
||||
auth.setApiKeyPrefix("Token");
|
||||
auth.processParams(queryParams, headerParams);
|
||||
|
||||
// no changes to query parameters
|
||||
assertEquals(0, queryParams.size());
|
||||
assertEquals(1, headerParams.size());
|
||||
assertEquals("Token my-api-token", headerParams.get("X-API-TOKEN"));
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package io.swagger.client.auth;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.*;
|
||||
|
||||
public class HttpBasicAuthTest {
|
||||
HttpBasicAuth auth = null;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
auth = new HttpBasicAuth();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessParams() {
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
auth.setUsername("my-username");
|
||||
auth.setPassword("my-password");
|
||||
auth.processParams(queryParams, headerParams);
|
||||
|
||||
// no changes to query parameters
|
||||
assertEquals(0, queryParams.size());
|
||||
assertEquals(1, headerParams.size());
|
||||
// the string below is base64-encoded result of "my-username:my-password" with the "Basic " prefix
|
||||
final String expected = "Basic bXktdXNlcm5hbWU6bXktcGFzc3dvcmQ=";
|
||||
assertEquals(expected, headerParams.get("Authorization"));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user