Skip to content
This repository has been archived by the owner on Apr 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #340 from servicecatalog/fb_k5_openstack_enhance
Browse files Browse the repository at this point in the history
Pull request Update keystone API v2 to v3
  • Loading branch information
redmond2683 authored Sep 27, 2016
2 parents 82c7949 + 4a69cef commit 181a7ef
Show file tree
Hide file tree
Showing 21 changed files with 1,097 additions and 424 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import org.junit.Before;
import org.junit.Test;

import org.oscm.app.openstack.exceptions.HeatException;
import org.oscm.app.v1_0.exceptions.APPlatformException;

Expand All @@ -25,36 +24,39 @@ public void setUp() throws Exception {
HeatProcessor.setURLStreamHandler(streamHandler);
}

@Test(expected = HeatException.class)
public void authenticate_malFormedURL() throws HeatException,
APPlatformException {
@Test
public void authenticate() throws HeatException, APPlatformException {
// given

// when
new KeystoneClient(new OpenStackConnection("xyz")).authenticate("user",
"password", "tenantName");
new KeystoneClient(new OpenStackConnection("https://xyz.de/v3/auth"))
.authenticate("user", "password", "domainName", "tenantId");
}

@Test
public void authenticate() throws HeatException, APPlatformException {
public void authenticateWithNoDomain()
throws HeatException, APPlatformException {
// given

// when
new KeystoneClient(new OpenStackConnection("http://xyz.de"))
.authenticate("user", "password", "tenantName");
new KeystoneClient(new OpenStackConnection("https://xyz.de/v3/auth"))
.authenticate("user", "password", "", "tenantId");
}

@Test
public void authenticate_http_666() throws HeatException,
APPlatformException {
public void authenticate_http_666()
throws HeatException, APPlatformException {
// given
int status = 666;
streamHandler.put("/tokens", new MockHttpURLConnection(status, ""));
streamHandler.put("/v3/auth/tokens",
new MockHttpsURLConnection(status, ""));

try {
// when
new KeystoneClient(new OpenStackConnection("http://xyz.de"))
.authenticate("user", "password", "tenantName");
new KeystoneClient(
new OpenStackConnection("https://xyz.de/v3/auth"))
.authenticate("user", "password", "domainName",
"tenantId");
assertTrue("Test must fail at this point", false);
} catch (RuntimeException ex) {
// then
Expand All @@ -63,38 +65,51 @@ public void authenticate_http_666() throws HeatException,
}
}

@Test(expected = HeatException.class)
public void authenticate_malFormedURL()
throws HeatException, APPlatformException {
// given

// when
new KeystoneClient(new OpenStackConnection("xyz")).authenticate("user",
"password", "domainName", "tenantId");
}

@Test(expected = RuntimeException.class)
public void authenticate_noJSONResponse() throws HeatException,
APPlatformException {
public void authenticate_noJSONResponse()
throws HeatException, APPlatformException {
// given
streamHandler.put("/tokens", new MockHttpURLConnection(200, ""));
streamHandler.put("/v3/auth/tokens",
new MockHttpsURLConnection(201, ""));

// when
new KeystoneClient(new OpenStackConnection("http://xyz.de"))
.authenticate("user", "password", "tenantName");
new KeystoneClient(new OpenStackConnection("https://xyz.de/v3/auth"))
.authenticate("user", "password", "domainName", "tenantId");

}

@Test(expected = APPlatformException.class)
public void authenticate_noHeatEndpoint() throws HeatException,
APPlatformException {
public void authenticate_noHeatEndpoint()
throws HeatException, APPlatformException {
// given
streamHandler.put("/tokens", new MockHttpURLConnection(200,
MockURLStreamHandler.respTokens(false, true)));
streamHandler.put("/v3/auth/tokens", new MockHttpsURLConnection(201,
MockURLStreamHandler.respTokens(false, true, true)));

// when
new KeystoneClient(new OpenStackConnection("http://xyz.de"))
.authenticate("user", "password", "tenantName");
new KeystoneClient(new OpenStackConnection("https://xyz.de/v3/auth"))
.authenticate("user", "password", "domainName", "tenantId");
}

@Test(expected = APPlatformException.class)
public void authenticate_noNovaEndpoint() throws HeatException,
APPlatformException {
public void authenticate_noNovaEndpoint()
throws HeatException, APPlatformException {
// given
streamHandler.put("/tokens", new MockHttpURLConnection(200,
MockURLStreamHandler.respTokens(true, false)));
streamHandler.put("/v3/auth/tokens", new MockHttpsURLConnection(201,
MockURLStreamHandler.respTokens(true, false, true)));

// when
new KeystoneClient(new OpenStackConnection("http://xyz.de"))
.authenticate("user", "password", "tenantName");
new KeystoneClient(new OpenStackConnection("https://xyz.de/v3/auth"))
.authenticate("user", "password", "domainName", "tenantId");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*******************************************************************************
*
* Copyright FUJITSU LIMITED 2016
*
* Creation Date: 26.07.2016
*
*******************************************************************************/
package org.oscm.app.openstack;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.security.cert.Certificate;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLPeerUnverifiedException;

public class MockHttpsURLConnection extends HttpsURLConnection {
private String error;
private String input;
private String output;
protected int responseCode;
private StringWriter inputWriter = new StringWriter();

public MockHttpsURLConnection(int responseCode, String output) {
super(null);
this.output = output;
this.responseCode = responseCode;

}

@Override
public String getCipherSuite() {
return null;
}

@Override
public Certificate[] getLocalCertificates() {
return null;
}

@Override
public Certificate[] getServerCertificates()
throws SSLPeerUnverifiedException {
return null;
}

@Override
public void disconnect() {

}

@Override
public boolean usingProxy() {
return false;
}

@Override
public void connect() throws IOException {

}
@Override
public InputStream getInputStream() throws IOException {
connect();
if (output == null) {
output = "";
}
return new ByteArrayInputStream(output.getBytes());
}

@Override
public InputStream getErrorStream() {
if (error == null) {
error = "";
}
return new ByteArrayInputStream(error.getBytes());
}

@Override
public OutputStream getOutputStream() throws IOException {
return new OutputStream() {
@Override
public void write(int b) throws IOException {
inputWriter.write(b);
}
};
}
public String getInput() {
if (!connected) {
throw new IllegalStateException("Not connected");
}
return input;
}

@Override
public int getResponseCode() throws IOException {
return responseCode;
}

@Override
public String getHeaderField(String name){
if((name).equals("X-Subject-Token")){
return "authToken";
}
return super.getHeaderField(name);
}
}
Loading

0 comments on commit 181a7ef

Please sign in to comment.