You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2014/07/28 12:29:31 UTC
[6/7] git commit: Adds integration test for ServerResource.getUser
Adds integration test for ServerResource.getUser
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/df487c93
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/df487c93
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/df487c93
Branch: refs/heads/master
Commit: df487c93d7111987e86e1cb955d8c25ae32bcde8
Parents: 29543c0
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Mon Jul 28 10:53:32 2014 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Mon Jul 28 10:53:32 2014 +0100
----------------------------------------------------------------------
.../ServerResourceIntegrationTest.java | 61 ++++++++++++++++++++
.../rest/resources/ServerResourceTest.java | 6 --
.../security/provider/TestSecurityProvider.java | 42 ++++++++++++++
3 files changed, 103 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/df487c93/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceIntegrationTest.java b/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceIntegrationTest.java
new file mode 100644
index 0000000..5805c9c
--- /dev/null
+++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceIntegrationTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package brooklyn.rest.resources;
+
+import static org.testng.Assert.assertEquals;
+
+import java.net.URI;
+
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.HttpClient;
+import org.eclipse.jetty.server.Server;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+import brooklyn.rest.BrooklynRestApiLauncher;
+import brooklyn.rest.BrooklynRestApiLauncherTestFixture;
+import brooklyn.rest.security.provider.TestSecurityProvider;
+import brooklyn.test.HttpTestUtils;
+import brooklyn.util.http.HttpTool;
+import brooklyn.util.http.HttpToolResponse;
+
+public class ServerResourceIntegrationTest extends BrooklynRestApiLauncherTestFixture {
+
+ @Test(groups = "Integration")
+ public void testGetUser() throws Exception {
+ Server server = useServerForTest(BrooklynRestApiLauncher.launcher()
+ .securityProvider(TestSecurityProvider.class)
+ .withoutJsgui()
+ .start());
+ assertEquals(getServerUser(server), TestSecurityProvider.USER);
+ }
+
+ private String getServerUser(Server server) throws Exception {
+ HttpClient client = HttpTool.httpClientBuilder()
+ .uri(getBaseUri(server))
+ .credentials(new UsernamePasswordCredentials(TestSecurityProvider.USER, TestSecurityProvider.PASSWORD))
+ .build();
+ HttpToolResponse response = HttpTool.httpGet(client, URI.create(getBaseUri() + "/v1/server/user"),
+ ImmutableMap.<String, String>of());
+ HttpTestUtils.assertHealthyStatusCode(response.getResponseCode());
+ return response.getContentAsString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/df487c93/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java b/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
index 8542b44..a540046 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
@@ -103,10 +103,4 @@ public class ServerResourceTest extends BrooklynRestResourceTest {
}});
}
- // Disabled as BrooklynPropertiesSecurityFilter is not loaded in tests and the server responds 204 No Content.
- @Test(groups = "WIP")
- public void testGetUser() throws Exception {
- String user = client().resource("/v1/server/user").get(String.class);
- assertEquals(user, Entitlements.getEntitlementContext().user());
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/df487c93/usage/rest-server/src/test/java/brooklyn/rest/security/provider/TestSecurityProvider.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/security/provider/TestSecurityProvider.java b/usage/rest-server/src/test/java/brooklyn/rest/security/provider/TestSecurityProvider.java
new file mode 100644
index 0000000..ccb89a6
--- /dev/null
+++ b/usage/rest-server/src/test/java/brooklyn/rest/security/provider/TestSecurityProvider.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package brooklyn.rest.security.provider;
+
+import javax.servlet.http.HttpSession;
+
+public class TestSecurityProvider implements SecurityProvider {
+
+ public static final String USER = "test";
+ public static final String PASSWORD = "opensesame";
+
+ @Override
+ public boolean isAuthenticated(HttpSession session) {
+ return false;
+ }
+
+ @Override
+ public boolean authenticate(HttpSession session, String user, String password) {
+ return USER.equals(user) && PASSWORD.equals(password);
+ }
+
+ @Override
+ public boolean logout(HttpSession session) {
+ return false;
+ }
+}