Permalink
Browse files

CFID-105: tweak tests and update README for BVT changes

Change-Id: Ib294d23d484ab5659f085b6f9f9c4479de85d8e6
  • Loading branch information...
1 parent ac05e71 commit e962246074a5799dd9dc246dd428e3bdfed96fdd @dsyer dsyer committed Jan 27, 2012
View
@@ -70,6 +70,42 @@ integration tests from the command line in one go with
(This might require an initial `mvn install` from the parent directory
to get the wars in your local repo first.)
+### BVTs
+
+There is a really simple cucumber feature spec (`--tag @uaa`) to
+verify that the UAS server is there. There is also a rake task to
+launch the integration tests from the `uaa` submodule in `vcap`.
+Typical usage for a local (`uaa.vcap.me`) instance:
+
+ $ cd vcap/tests
+ $ rake bvt:run_uaa
+
+To modify the runtime parameters you can provide a `uaa.yml` and set the
+env var `CLOUD_FOUNDRY_CONFIG_PATH`, e.g.
+
+ $ cat > /tmp/uaa.yml
+ uaa:
+ host: uaa.appcloud21.dev.mozycloud
+ test:
+ username: dev@cloudfoundry.org # defaults to vcap_tester@vmware.com
+ password: changeme
+ email: dev@cloudfoundry.org
+ $ CLOUD_FOUNDRY_CONFIG_PATH=/tmp rake bvt:run_uaa
+
+The tests will usually fail on the first run because of the 1 sec
+granularity of the timestamp on the tokens in the cloud_controller (so
+duplicate tokens will be rejected by the server). When you run the
+second and subsequent times they should pass because new token values
+will be obtained from the server.
+
+You can also change individual properties on the command line with
+`UAA_ARGS`, which are passed on to the mvn command line, or with
+MAVEN_OPTS which are passed on to the shell executing mvn, e.g.
+
+ $ UAA_ARGS=-Duaa=uaa.appcloud21.dev.mozycloud rake bvt:run_uaa
+
+N.B. MAVEN_OPTS cannot be used to set JVM system properties for the tests, but it can be used to set memory limits for the process etc.
+
## Inventory
There are actually several projects here, the main `uaa` server application and some samples:
@@ -27,21 +27,24 @@
/**
* Convenience for setting up a lightweight local HTTP server to provide legacy style (cloud_conttoller) tokens.
- *
+ *
* @author Dave Syer
- *
+ *
*/
@SuppressWarnings("restriction")
public class LegacyTokenServer {
private static final Log logger = LogFactory.getLog(LegacyTokenServer.class);
-
+
private RandomValueStringGenerator generator = new RandomValueStringGenerator();
private SimpleHttpServerFactoryBean factory;
- private int port;
- private final String expectedpassword;
+ private final int port;
+
+ private String expectedpassword;
+
+ private String tokenValue;
public LegacyTokenServer() {
this(8888, null);
@@ -50,12 +53,29 @@ public LegacyTokenServer() {
public LegacyTokenServer(int port) {
this(port, null);
}
-
+
public LegacyTokenServer(int port, String expectedpassword) {
this.port = port;
this.expectedpassword = expectedpassword;
}
+ /**
+ * @param expectedpassword the expected password to set
+ */
+ public void setExpectedpassword(String expectedpassword) {
+ this.expectedpassword = expectedpassword;
+ }
+
+ /**
+ * The value of teh access token to return on successful authentication. If null the value will be randomly
+ * generated.
+ *
+ * @param tokenValue the token value to set
+ */
+ public void setTokenValue(String tokenValue) {
+ this.tokenValue = tokenValue;
+ }
+
public void init() throws Exception {
factory = new SimpleHttpServerFactoryBean();
factory.setPort(port);
@@ -72,17 +92,19 @@ public void handle(HttpExchange exchange) throws IOException {
byte[] content;
boolean authenticated = false;
- if (expectedpassword!=null) {
- authenticated = body.equals("{\"password\":\""+expectedpassword+"\"}");
- } else {
+ if (expectedpassword != null) {
+ authenticated = body.equals("{\"password\":\"" + expectedpassword + "\"}");
+ }
+ else {
authenticated = body.contains("{\"password\":\"");
}
if (authenticated) {
code = 200;
- String token = generator.generate();
+ String token = tokenValue!=null ? tokenValue : generator.generate();
content = String.format("{\"token\":\"%s\"}", token).getBytes("UTF-8");
logger.debug("Successful authentication with token=" + token);
- } else {
+ }
+ else {
code = 403;
content = "".getBytes("UTF-8");
logger.debug("Forbidden");
@@ -47,6 +47,14 @@ private TestAccountSetup(String legacyProfileName) {
tokenServer = null;
if (isLegacy()) {
tokenServer = new LegacyTokenServer();
+ try {
+ logger.debug("Starting legacy token server");
+ tokenServer.init();
+ }
+ catch (Exception e) {
+ logger.error("Could not start legacy token server", e);
+ Assert.fail("Could not start legacy token server");
+ }
}
}
@@ -72,20 +80,6 @@ public String getEmail() {
}
@Override
- public void starting(FrameworkMethod method) {
- if (tokenServer != null) {
- try {
- logger.debug("Starting legacy token server");
- tokenServer.init();
- }
- catch (Exception e) {
- logger.error("Could not start legacy token server", e);
- Assert.fail("Could not start legacy token server");
- }
- }
- }
-
- @Override
public void finished(FrameworkMethod method) {
if (tokenServer != null) {
try {

0 comments on commit e962246

Please sign in to comment.