knox git commit: KNOX-1054 - Make DefaultURLManager thread-safe (Phil Zampino via Sandeep More)

2017-09-20 Thread more
Repository: knox
Updated Branches:
  refs/heads/master 2666894bc -> d3f507f94


KNOX-1054 - Make DefaultURLManager thread-safe (Phil Zampino via Sandeep More)


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/d3f507f9
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/d3f507f9
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/d3f507f9

Branch: refs/heads/master
Commit: d3f507f9424b7deb355696c1c6d5f5aad142157d
Parents: 2666894
Author: Sandeep More 
Authored: Wed Sep 20 21:47:35 2017 -0400
Committer: Sandeep More 
Committed: Wed Sep 20 21:47:35 2017 -0400

--
 .../hadoop/gateway/ha/provider/impl/DefaultURLManager.java  | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/d3f507f9/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultURLManager.java
--
diff --git 
a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultURLManager.java
 
b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultURLManager.java
index 484a580..e76be7d 100644
--- 
a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultURLManager.java
+++ 
b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/DefaultURLManager.java
@@ -24,7 +24,6 @@ import 
org.apache.hadoop.gateway.ha.provider.impl.i18n.HaMessages;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
 
 import java.net.URI;
-import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
@@ -34,8 +33,6 @@ public class DefaultURLManager implements URLManager {
 
   private ConcurrentLinkedQueue urls = new ConcurrentLinkedQueue<>();
 
-  public DefaultURLManager() {
-  }
 
   @Override
   public boolean supportsConfig(HaServiceConfig config) {
@@ -48,7 +45,7 @@ public class DefaultURLManager implements URLManager {
   }
 
   @Override
-  public String getActiveURL() {
+  public synchronized String getActiveURL() {
 return urls.peek();
   }
 
@@ -68,13 +65,13 @@ public class DefaultURLManager implements URLManager {
   }
 
   @Override
-  public List getURLs() {
+  public synchronized List getURLs() {
 return Lists.newArrayList(urls.iterator());
   }
 
   @Override
   public synchronized void setURLs(List urls) {
-if ( urls != null && !urls.isEmpty()) {
+if (urls != null && !urls.isEmpty()) {
   this.urls.clear();
   this.urls.addAll(urls);
 }



[04/12] knox git commit: KNOX-1047 - Add some tests for the Knox Token Service

2017-09-20 Thread more
KNOX-1047 - Add some tests for the Knox Token Service


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/3557612d
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/3557612d
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/3557612d

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: 3557612d5a5d904c3dfa61ba03cccfbbd365b296
Parents: 4978951
Author: Colm O hEigeartaigh 
Authored: Tue Sep 19 12:17:59 2017 +0100
Committer: Colm O hEigeartaigh 
Committed: Tue Sep 19 12:17:59 2017 +0100

--
 .../federation/AbstractJWTFilterTest.java   |  14 +-
 .../federation/JWTFederationFilterTest.java |   1 -
 .../federation/SSOCookieProviderTest.java   |   1 -
 gateway-service-knoxtoken/pom.xml   |  29 ++-
 .../service/knoxtoken/TokenResource.java|  31 +--
 .../knoxtoken/TokenServiceResourceTest.java | 256 ++-
 6 files changed, 293 insertions(+), 39 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/3557612d/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/AbstractJWTFilterTest.java
--
diff --git 
a/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/AbstractJWTFilterTest.java
 
b/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/AbstractJWTFilterTest.java
index 6f221a9..d477f1f 100644
--- 
a/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/AbstractJWTFilterTest.java
+++ 
b/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/AbstractJWTFilterTest.java
@@ -60,7 +60,7 @@ import 
org.apache.hadoop.gateway.services.security.token.impl.JWTToken;
 import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Assert;
-import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.nimbusds.jose.*;
@@ -74,16 +74,16 @@ public abstract class AbstractJWTFilterTest  {
   private static final String dnTemplate = 
"CN={0},OU=Test,O=Hadoop,L=Test,ST=Test,C=US";
 
   protected AbstractJWTFilter handler = null;
-  protected RSAPublicKey publicKey = null;
-  protected RSAPrivateKey privateKey = null;
-  protected String pem = null;
+  protected static RSAPublicKey publicKey = null;
+  protected static RSAPrivateKey privateKey = null;
+  protected static String pem = null;
 
   protected abstract void setTokenOnRequest(HttpServletRequest request, 
SignedJWT jwt);
   protected abstract void setGarbledTokenOnRequest(HttpServletRequest request, 
SignedJWT jwt);
   protected abstract String getAudienceProperty();
   protected abstract String getVerificationPemProperty();
 
-  private String buildDistinguishedName(String hostname) {
+  private static String buildDistinguishedName(String hostname) {
 MessageFormat headerFormatter = new MessageFormat(dnTemplate);
 String[] paramArray = new String[1];
 paramArray[0] = hostname;
@@ -91,8 +91,8 @@ public abstract class AbstractJWTFilterTest  {
 return dn;
   }
 
-  @Before
-  public void setup() throws Exception, NoSuchAlgorithmException {
+  @BeforeClass
+  public static void generateKeys() throws Exception, NoSuchAlgorithmException 
{
 KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
 kpg.initialize(2048);
 KeyPair KPair = kpg.generateKeyPair();

http://git-wip-us.apache.org/repos/asf/knox/blob/3557612d/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/JWTFederationFilterTest.java
--
diff --git 
a/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/JWTFederationFilterTest.java
 
b/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/JWTFederationFilterTest.java
index d19d999..99a3780 100644
--- 
a/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/JWTFederationFilterTest.java
+++ 
b/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/JWTFederationFilterTest.java
@@ -32,7 +32,6 @@ public class JWTFederationFilterTest extends 
AbstractJWTFilterTest {
 
 @Before
 public void setup() throws Exception, NoSuchAlgorithmException {
-  super.setup();
   handler = new TestJWTFederationFilter();
   ((TestJWTFederationFilter) handler).setTokenService(new 
TestJWTokenAuthority(publicKey));
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/3557612d/gateway-provider-security-jwt/src/test/java/org/apache/hadoop/gateway/provider/federation/SSOCookieProviderTest.java

[09/12] knox git commit: Merge remote-tracking branch 'origin/master' into KNOX-998-Package_Restructuring

2017-09-20 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/416ee7c1/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java
--
diff --cc 
gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java
index 0fbd6db,000..3adf41a
mode 100644,00..100644
--- 
a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java
+++ 
b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java
@@@ -1,4515 -1,0 +1,4508 @@@
 +/**
 + * 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 org.apache.knox.gateway;
 +
 +import java.io.ByteArrayOutputStream;
 +import java.io.File;
 +import java.io.FileFilter;
 +import java.io.FileNotFoundException;
 +import java.io.IOException;
 +import java.io.PrintStream;
 +import java.io.StringWriter;
 +import java.net.InetAddress;
 +import java.net.InetSocketAddress;
 +import java.net.URI;
 +import java.net.URISyntaxException;
 +import java.net.URL;
 +import java.nio.charset.Charset;
 +import java.util.HashMap;
 +import java.util.Map;
 +import java.util.Map.Entry;
 +import javax.ws.rs.core.MediaType;
 +
 +import io.restassured.RestAssured;
 +import io.restassured.http.ContentType;
 +import io.restassured.http.Cookie;
 +import io.restassured.http.Header;
 +import io.restassured.path.json.JsonPath;
 +import io.restassured.response.Response;
 +import io.restassured.specification.ResponseSpecification;
 +import com.mycila.xmltool.XMLDoc;
 +import com.mycila.xmltool.XMLTag;
 +import org.apache.commons.io.filefilter.WildcardFileFilter;
 +import org.apache.commons.lang3.ArrayUtils;
 +import org.apache.knox.gateway.util.KnoxCLI;
 +import org.apache.hadoop.test.TestUtils;
 +import org.apache.hadoop.test.category.MediumTests;
 +import org.apache.hadoop.test.category.VerifyTest;
 +import org.apache.hadoop.test.mock.MockRequestMatcher;
 +import org.apache.http.HttpHost;
 +import org.apache.http.HttpResponse;
 +import org.apache.http.HttpStatus;
 +import org.apache.http.auth.AuthScope;
 +import org.apache.http.auth.UsernamePasswordCredentials;
 +import org.apache.http.client.AuthCache;
 +import org.apache.http.client.CredentialsProvider;
 +import org.apache.http.client.methods.HttpGet;
 +import org.apache.http.client.methods.HttpPost;
 +import org.apache.http.client.protocol.HttpClientContext;
 +import org.apache.http.entity.StringEntity;
 +import org.apache.http.impl.auth.BasicScheme;
 +import org.apache.http.impl.client.BasicAuthCache;
 +import org.apache.http.impl.client.BasicCredentialsProvider;
 +import org.apache.http.impl.client.CloseableHttpClient;
 +import org.apache.http.impl.client.HttpClientBuilder;
 +import org.apache.http.util.EntityUtils;
 +import org.apache.velocity.Template;
 +import org.apache.velocity.VelocityContext;
 +import org.apache.velocity.app.VelocityEngine;
 +import org.apache.velocity.runtime.RuntimeConstants;
 +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 +import org.hamcrest.CoreMatchers;
 +import org.hamcrest.Matcher;
 +import org.hamcrest.MatcherAssert;
 +import org.hamcrest.Matchers;
 +import org.junit.After;
 +import org.junit.AfterClass;
 +import org.junit.Assert;
 +import org.junit.BeforeClass;
 +import org.junit.Test;
 +import org.junit.experimental.categories.Category;
 +import org.slf4j.Logger;
 +import org.slf4j.LoggerFactory;
 +
 +import static io.restassured.RestAssured.given;
 +import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
 +import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
 +import static org.hamcrest.CoreMatchers.*;
 +import static org.hamcrest.Matchers.containsString;
 +import static org.hamcrest.Matchers.greaterThan;
 +import static org.hamcrest.text.IsEmptyString.isEmptyString;
 +import static org.junit.Assert.assertThat;
 +import static org.junit.Assert.assertTrue;
 +import static org.xmlmatchers.XmlMatchers.isEquivalentTo;
 +import static org.xmlmatchers.transform.XmlConverters.the;
 +import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
 +
 +@Category( { VerifyTest.class, MediumTests.class } )
 +public class GatewayBasicFuncTest {
 +
 +  private static final Charset UTF8 = Charset.f

[08/12] knox git commit: Merge remote-tracking branch 'origin/master' into KNOX-998-Package_Restructuring

2017-09-20 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/416ee7c1/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java
--
diff --cc 
gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java
index e9442cd,000..9349dca
mode 100644,00..100644
--- 
a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java
+++ 
b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayDeployFuncTest.java
@@@ -1,315 -1,0 +1,315 @@@
 +/**
 + * 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 org.apache.knox.gateway;
 +
 +import io.restassured.response.Response;
 +import com.mycila.xmltool.XMLDoc;
 +import com.mycila.xmltool.XMLTag;
 +import org.apache.commons.io.FileUtils;
 +import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 +import org.apache.knox.gateway.config.GatewayConfig;
 +import org.apache.knox.gateway.security.ldap.SimpleLdapDirectoryServer;
 +import org.apache.knox.gateway.services.DefaultGatewayServices;
 +import org.apache.knox.gateway.services.ServiceLifecycleException;
 +import org.apache.hadoop.test.TestUtils;
 +import org.apache.hadoop.test.category.ReleaseTest;
 +import org.apache.http.HttpStatus;
 +import org.apache.log4j.Appender;
 +import org.hamcrest.MatcherAssert;
 +import org.junit.After;
 +import org.junit.AfterClass;
 +import org.junit.Before;
 +import org.junit.BeforeClass;
 +import org.junit.Test;
 +import org.junit.experimental.categories.Category;
 +import org.slf4j.Logger;
 +import org.slf4j.LoggerFactory;
 +
 +import java.io.File;
 +import java.io.FileOutputStream;
 +import java.io.FilenameFilter;
 +import java.io.IOException;
 +import java.util.Enumeration;
 +import java.util.HashMap;
 +import java.util.Map;
 +import java.util.UUID;
 +import java.util.regex.Pattern;
 +
 +import static io.restassured.RestAssured.given;
 +import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
 +import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
 +import static org.hamcrest.CoreMatchers.containsString;
 +import static org.hamcrest.CoreMatchers.is;
 +import static org.hamcrest.CoreMatchers.notNullValue;
 +import static org.hamcrest.Matchers.greaterThan;
 +import static org.junit.Assert.assertThat;
 +
 +@Category(ReleaseTest.class)
 +public class GatewayDeployFuncTest {
 +
 +  private static Logger LOG = LoggerFactory.getLogger( 
GatewayDeployFuncTest.class );
 +
 +  public static Enumeration appenders;
 +  public static GatewayConfig config;
 +  public static GatewayServer gateway;
 +  public static File gatewayHome;
 +  public static String gatewayUrl;
 +  public static String clusterUrl;
 +  private static GatewayTestDriver driver = new GatewayTestDriver();
 +
 +  @BeforeClass
 +  public static void setupSuite() throws Exception {
 +LOG_ENTER();
 +//appenders = NoOpAppender.setUp();
 +driver.setupLdap(0);
 +LOG_EXIT();
 +  }
 +
 +  @AfterClass
 +  public static void cleanupSuite() throws Exception {
 +LOG_ENTER();
 +driver.cleanup();
 +//FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) );
 +//NoOpAppender.tearDown( appenders );
 +LOG_EXIT();
 +  }
 +
 +  @Before
 +  public void setupGateway() throws Exception {
 +
 +File targetDir = new File( System.getProperty( "user.dir" ), "target" );
 +File gatewayDir = new File( targetDir, "gateway-home-" + 
UUID.randomUUID() );
 +gatewayDir.mkdirs();
 +gatewayHome = gatewayDir;
 +
 +GatewayTestConfig testConfig = new GatewayTestConfig();
 +config = testConfig;
 +testConfig.setGatewayHomeDir( gatewayDir.getAbsolutePath() );
 +
 +File topoDir = new File( testConfig.getGatewayTopologyDir() );
 +topoDir.mkdirs();
 +
 +File deployDir = new File( testConfig.getGatewayDeploymentDir() );
 +deployDir.mkdirs();
 +
 +DefaultGatewayServices srvcs = new DefaultGatewayServices();
 +Map options = new HashMap<>();
 +options.put( "persist-master", "false" );
 +options.put( "master", "password" );
 +try {
 +  srvcs.init( testConfig, options );
 +} catch ( ServiceLifecycleException e ) {
 +  e.printStackTrace(); // I18N not req

[11/12] knox git commit: Merge remote-tracking branch 'origin/master' into KNOX-998-Package_Restructuring

2017-09-20 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/416ee7c1/gateway-service-knoxtoken/src/test/java/org/apache/knox/gateway/service/knoxtoken/TokenServiceResourceTest.java
--
diff --cc 
gateway-service-knoxtoken/src/test/java/org/apache/knox/gateway/service/knoxtoken/TokenServiceResourceTest.java
index db66c8e,000..dc76005
mode 100644,00..100644
--- 
a/gateway-service-knoxtoken/src/test/java/org/apache/knox/gateway/service/knoxtoken/TokenServiceResourceTest.java
+++ 
b/gateway-service-knoxtoken/src/test/java/org/apache/knox/gateway/service/knoxtoken/TokenServiceResourceTest.java
@@@ -1,52 -1,0 +1,307 @@@
 +/**
 + * 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 org.apache.knox.gateway.service.knoxtoken;
 +
++import org.apache.knox.gateway.service.knoxtoken.TokenResource;
++import org.apache.knox.gateway.services.GatewayServices;
++import org.apache.knox.gateway.services.security.token.JWTokenAuthority;
++import org.apache.knox.gateway.services.security.token.TokenServiceException;
++import org.apache.knox.gateway.services.security.token.impl.JWT;
++import org.apache.knox.gateway.services.security.token.impl.JWTToken;
++import org.easymock.EasyMock;
 +import org.junit.Assert;
++import org.junit.BeforeClass;
 +import org.junit.Test;
 +
++import com.nimbusds.jose.JWSSigner;
++import com.nimbusds.jose.JWSVerifier;
++import com.nimbusds.jose.crypto.RSASSASigner;
++import com.nimbusds.jose.crypto.RSASSAVerifier;
++
 +import java.util.Map;
++
++import javax.security.auth.Subject;
++import javax.servlet.ServletContext;
++import javax.servlet.http.HttpServletRequest;
++import javax.servlet.http.HttpServletResponse;
++import javax.ws.rs.core.Response;
++
++import static org.junit.Assert.*;
++
++import java.io.PrintWriter;
++import java.io.StringWriter;
++import java.security.KeyPair;
++import java.security.KeyPairGenerator;
++import java.security.NoSuchAlgorithmException;
++import java.security.Principal;
++import java.security.interfaces.RSAPrivateKey;
++import java.security.interfaces.RSAPublicKey;
++import java.util.ArrayList;
++import java.util.Arrays;
++import java.util.Collections;
 +import java.util.HashMap;
++import java.util.List;
 +
 +/**
-  *
++ * Some tests for the token service
 + */
 +public class TokenServiceResourceTest {
 +
++  protected static RSAPublicKey publicKey;
++  protected static RSAPrivateKey privateKey;
++
++  @BeforeClass
++  public static void setup() throws Exception, NoSuchAlgorithmException {
++KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
++kpg.initialize(1024);
++KeyPair KPair = kpg.generateKeyPair();
++
++publicKey = (RSAPublicKey) KPair.getPublic();
++privateKey = (RSAPrivateKey) KPair.getPrivate();
++  }
++
 +  @Test
 +  public void testTokenService() throws Exception {
 +Assert.assertTrue(true);
 +  }
 +
 +  @Test
 +  public void testClientData() throws Exception {
 +TokenResource tr = new TokenResource();
 +
 +Map clientDataMap = new HashMap<>();
 +tr.addClientDataToMap("cookie.name=hadoop-jwt,test=value".split(","), 
clientDataMap);
 +Assert.assertTrue(clientDataMap.size() == 2);
 +
 +clientDataMap = new HashMap<>();
 +tr.addClientDataToMap("cookie.name=hadoop-jwt".split(","), clientDataMap);
 +Assert.assertTrue(clientDataMap.size() == 1);
 +
 +clientDataMap = new HashMap<>();
 +tr.addClientDataToMap("".split(","), clientDataMap);
 +Assert.assertTrue(clientDataMap.size() == 0);
 +  }
++
++  @Test
++  public void testGetToken() throws Exception {
++TokenResource tr = new TokenResource();
++
++ServletContext context = EasyMock.createNiceMock(ServletContext.class);
++//tr.context = context;
++// tr.init();
++
++HttpServletRequest request = 
EasyMock.createNiceMock(HttpServletRequest.class);
++
EasyMock.expect(request.getServletContext()).andReturn(context).anyTimes();
++Principal principal = EasyMock.createNiceMock(Principal.class);
++EasyMock.expect(principal.getName()).andReturn("alice").anyTimes();
++
EasyMock.expect(request.getUserPrincipal()).andReturn(principal).anyTimes();
++
++GatewayServices services = E

[06/12] knox git commit: KNOX-1052 - Add some tests for the Knox SSO Service

2017-09-20 Thread more
KNOX-1052 - Add some tests for the Knox SSO Service


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/2666894b
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/2666894b
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/2666894b

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: 2666894bc84281ed78890110ab15b009fa5f2830
Parents: a5a8825
Author: Colm O hEigeartaigh 
Authored: Wed Sep 20 11:09:54 2017 +0100
Committer: Colm O hEigeartaigh 
Committed: Wed Sep 20 11:09:54 2017 +0100

--
 gateway-service-knoxsso/pom.xml |  11 +-
 .../gateway/service/knoxsso/WebSSOResource.java |  20 +-
 .../service/knoxsso/WebSSOResourceTest.java | 304 ++-
 3 files changed, 308 insertions(+), 27 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/2666894b/gateway-service-knoxsso/pom.xml
--
diff --git a/gateway-service-knoxsso/pom.xml b/gateway-service-knoxsso/pom.xml
index f5018a2..e6b6ca5 100644
--- a/gateway-service-knoxsso/pom.xml
+++ b/gateway-service-knoxsso/pom.xml
@@ -59,9 +59,10 @@
   gateway-test-utils
   test
 
-  
-  org.easymock
-  easymock
-  test
-
+
+  org.easymock
+  easymock
+  test
+
+  
 

http://git-wip-us.apache.org/repos/asf/knox/blob/2666894b/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
--
diff --git 
a/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
 
b/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
index 7cc5378..0d9e6dd 100644
--- 
a/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
+++ 
b/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
@@ -23,6 +23,7 @@ import java.net.URISyntaxException;
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -74,14 +75,14 @@ public class WebSSOResource {
   private long tokenTTL = 3l;
   private String whitelist = null;
   private String domainSuffix = null;
-  private String[] targetAudiences = null;
+  private List targetAudiences = new ArrayList<>();
   private boolean enableSession = false;
 
   @Context
-  private HttpServletRequest request;
+  HttpServletRequest request;
 
   @Context
-  private HttpServletResponse response;
+  HttpServletResponse response;
 
   @Context
   ServletContext context;
@@ -124,7 +125,10 @@ public class WebSSOResource {
 
 String audiences = 
context.getInitParameter(SSO_COOKIE_TOKEN_AUDIENCES_PARAM);
 if (audiences != null) {
-  targetAudiences = audiences.split(",");
+  String[] auds = audiences.split(",");
+  for (int i = 0; i < auds.length; i++) {
+targetAudiences.add(auds[i]);
+  }
 }
 
 String ttl = context.getInitParameter(SSO_COOKIE_TOKEN_TTL_PARAM);
@@ -180,14 +184,10 @@ public class WebSSOResource {
 
 try {
   JWT token = null;
-  if (targetAudiences == null || targetAudiences.length == 0) {
+  if (targetAudiences.isEmpty()) {
 token = ts.issueToken(p, "RS256", getExpiry());
   } else {
-ArrayList aud = new ArrayList();
-for (int i = 0; i < targetAudiences.length; i++) {
-  aud.add(targetAudiences[i]);
-}
-token = ts.issueToken(p, aud, "RS256", getExpiry());
+token = ts.issueToken(p, targetAudiences, "RS256", getExpiry());
   }
 
   // Coverity CID 1327959

http://git-wip-us.apache.org/repos/asf/knox/blob/2666894b/gateway-service-knoxsso/src/test/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResourceTest.java
--
diff --git 
a/gateway-service-knoxsso/src/test/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResourceTest.java
 
b/gateway-service-knoxsso/src/test/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResourceTest.java
index 73910dd..c953c91 100644
--- 
a/gateway-service-knoxsso/src/test/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResourceTest.java
+++ 
b/gateway-service-knoxsso/src/test/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResourceTest.java
@@ -17,15 +17,65 @@
  */
 package org.apache.hadoop.gateway.service.knoxsso;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.No

[02/12] knox git commit: KNOX-1044 - Change Rest Assured "expect" to "then"

2017-09-20 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/4978951c/gateway-test/src/test/java/org/apache/hadoop/gateway/WebHdfsHaFuncTest.java
--
diff --git 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/WebHdfsHaFuncTest.java 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/WebHdfsHaFuncTest.java
index 1fc8c33..e2d679b 100644
--- 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/WebHdfsHaFuncTest.java
+++ 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/WebHdfsHaFuncTest.java
@@ -171,7 +171,7 @@ public class WebHdfsHaFuncTest {
 .auth().preemptive().basic(username, password)
 .header("X-XSRF-Header", "jksdhfkhdsf")
 .queryParam("op", "LISTSTATUS")
-.expect()
+.then()
 .log().ifError()
 .statusCode(HttpStatus.SC_OK)
 .body("FileStatuses.FileStatus[0].pathSuffix", is("app-logs"))
@@ -186,7 +186,7 @@ public class WebHdfsHaFuncTest {
   LOG_ENTER();
   String username = "hdfs";
   String password = "hdfs-password";
-  //Shutdown master and expect standby to serve the list response
+  //Shutdown master and then standby to serve the list response
   masterServer.stop();
   standbyServer.expect()
 .method("GET")
@@ -201,7 +201,7 @@ public class WebHdfsHaFuncTest {
 .auth().preemptive().basic(username, password)
 .header("X-XSRF-Header", "jksdhfkhdsf")
 .queryParam("op", "LISTSTATUS")
-.expect()
+.then()
 .log().ifError()
 .statusCode(HttpStatus.SC_OK)
 .body("FileStatuses.FileStatus[0].pathSuffix", is("app-logs"))
@@ -216,14 +216,14 @@ public class WebHdfsHaFuncTest {
   LOG_ENTER();
   String username = "hdfs";
   String password = "hdfs-password";
-  //Shutdown master and expect standby to serve the list response
+  //Shutdown master and then standby to serve the list response
   masterServer.stop();
   standbyServer.stop();
   given()
 .auth().preemptive().basic(username, password)
 .header("X-XSRF-Header", "jksdhfkhdsf")
 .queryParam("op", "LISTSTATUS")
-.expect()
+.then()
 //.log().ifError()
 .statusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
 .when().get(driver.getUrl("WEBHDFS") + "/v1/");
@@ -263,7 +263,7 @@ public class WebHdfsHaFuncTest {
 .auth().preemptive().basic(username, password)
 .header("X-XSRF-Header", "jksdhfkhdsf")
 .queryParam("op", "LISTSTATUS")
-.expect()
+.then()
 .log().ifError()
 .statusCode(HttpStatus.SC_OK)
 .body("FileStatuses.FileStatus[0].pathSuffix", is("app-logs"))
@@ -319,7 +319,7 @@ public class WebHdfsHaFuncTest {
 .auth().preemptive().basic(username, password)
 .header("X-XSRF-Header", "jksdhfkhdsf")
 .queryParam("op", "LISTSTATUS")
-.expect()
+.then()
 //.log().ifError()
 .statusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
 .when().get(driver.getUrl("WEBHDFS") + "/v1/");
@@ -359,7 +359,7 @@ public class WebHdfsHaFuncTest {
 .header("X-XSRF-Header", "jksdhfkhdsf")
 .queryParam("op", "RENAME")
 .queryParam("destination", "/user/hdfs/foo.txt")
-.expect()
+.then()
 .log().ifError()
 .statusCode(HttpStatus.SC_OK)
 .body("boolean", is(true))
@@ -396,7 +396,7 @@ public class WebHdfsHaFuncTest {
 .auth().preemptive().basic(username, password)
 .header("X-XSRF-Header", "jksdhfkhdsf")
 .queryParam("op", "MKDIRS")
-.expect()
+.then()
 .log().ifError()
 .statusCode(HttpStatus.SC_OK)
 .body("boolean", is(true))
@@ -456,7 +456,7 @@ public class WebHdfsHaFuncTest {
 .header("X-XSRF-Header", "jksdhfkhdsf")
 .queryParam("op", "RENAME")
 .queryParam("destination", "/user/hdfs/foo.txt")
-.expect()
+.then()
 //.log().ifError()
 .statusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
 .when().post(driver.getUrl("WEBHDFS") + "/v1/user/hdfs/foo.txt");



[03/12] knox git commit: KNOX-1044 - Change Rest Assured "expect" to "then"

2017-09-20 Thread more
KNOX-1044 - Change Rest Assured "expect" to "then"


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/4978951c
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/4978951c
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/4978951c

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: 4978951cc14bd63db2eace832b4db5544b80bee0
Parents: aac2054
Author: Colm O hEigeartaigh 
Authored: Fri Sep 15 10:02:47 2017 +0100
Committer: Colm O hEigeartaigh 
Committed: Fri Sep 15 10:02:47 2017 +0100

--
 .../gateway/AmbariServiceDefinitionTest.java|  14 +-
 .../hadoop/gateway/GatewayAdminFuncTest.java|   2 +-
 .../gateway/GatewayAdminTopologyFuncTest.java   |  60 ++---
 .../hadoop/gateway/GatewayAppFuncTest.java  |  68 +++---
 .../hadoop/gateway/GatewayBasicFuncTest.java| 224 +--
 .../hadoop/gateway/GatewayDeployFuncTest.java   |   2 +-
 .../hadoop/gateway/GatewayHealthFuncTest.java   |   4 +-
 .../GatewayLdapDynamicGroupFuncTest.java|   4 +-
 .../gateway/GatewayLdapGroupFuncTest.java   |   4 +-
 .../gateway/GatewayLdapPosixGroupFuncTest.java  |   4 +-
 .../gateway/GatewayLocalServiceFuncTest.java|   2 +-
 .../hadoop/gateway/GatewayMultiFuncTest.java|  26 +--
 .../GatewayPortMappingDisableFeatureTest.java   |   2 +-
 .../gateway/GatewayPortMappingFailTest.java |   2 +-
 .../gateway/GatewayPortMappingFuncTest.java |   2 +-
 .../hadoop/gateway/GatewaySampleFuncTest.java   |   2 +-
 .../apache/hadoop/gateway/Knox242FuncTest.java  |   4 +-
 .../hadoop/gateway/WebHdfsHaFuncTest.java   |  20 +-
 18 files changed, 223 insertions(+), 223 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/4978951c/gateway-test/src/test/java/org/apache/hadoop/gateway/AmbariServiceDefinitionTest.java
--
diff --git 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/AmbariServiceDefinitionTest.java
 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/AmbariServiceDefinitionTest.java
index 2d02966..84b3ad3 100644
--- 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/AmbariServiceDefinitionTest.java
+++ 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/AmbariServiceDefinitionTest.java
@@ -177,7 +177,7 @@ public class AmbariServiceDefinitionTest {
 String body = given()
 //.log().all()
 .auth().preemptive().basic( username, password )
-.expect()
+.then()
 //.log().all()
 .statusCode( HttpStatus.SC_OK )
 .contentType( "text/plain" )
@@ -212,7 +212,7 @@ public class AmbariServiceDefinitionTest {
 
 String body = given()
 .auth().preemptive().basic( username, password )
-.expect()
+.then()
 .statusCode( HttpStatus.SC_OK )
 .contentType( "text/plain" )
 .when().get( serviceUrl ).asString();
@@ -247,7 +247,7 @@ public class AmbariServiceDefinitionTest {
  given()
 .auth().preemptive().basic( username, password )
 .queryParam("ServiceComponentInfo/component_name", 
"APP_TIMELINE_SERVER|ServiceComponentInfo/category=MASTER")
-.expect()
+.then()
 .statusCode( HttpStatus.SC_OK )
 .contentType( "text/plain" )
 .when().get( serviceUrl ).asString();
@@ -274,7 +274,7 @@ public class AmbariServiceDefinitionTest {
 
 String body = given()
 .auth().preemptive().basic( username, password )
-.expect()
+.then()
 .statusCode( HttpStatus.SC_OK )
 .contentType( "text/plain" )
 .when().get( serviceUrl ).asString();
@@ -302,8 +302,8 @@ public class AmbariServiceDefinitionTest {
 
 String body = given()
 .auth().preemptive().basic( username, password )
-.content(IOUtils.toByteArray(TestUtils.getResourceStream( DAT, 
"post-data-wrong-type.json")))
-.expect()
+.body(IOUtils.toByteArray(TestUtils.getResourceStream( DAT, 
"post-data-wrong-type.json")))
+.then()
 .statusCode( HttpStatus.SC_OK )
 .contentType( "application/x-www-form-urlencoded" )
 .when().post( serviceUrl ).asString();
@@ -335,7 +335,7 @@ public class AmbariServiceDefinitionTest {
 
 String body = given()
 .auth().preemptive().basic( username, password )
-.expect()
+.then()
 .statusCode( HttpStatus.SC_OK )
 .contentType( "text/plain" )
 .when().get( serviceUrl ).asString();

http://git-wip-us.apache.org/repos/asf/knox/blob/4978951c/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java
--
diff --git 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminFuncTest.java
 
b/gateway-test/src/test/java/or

[12/12] knox git commit: Merge remote-tracking branch 'origin/master' into KNOX-998-Package_Restructuring

2017-09-20 Thread more
Merge remote-tracking branch 'origin/master' into KNOX-998-Package_Restructuring

# Conflicts:
#   
gateway-service-knoxsso/src/test/java/org/apache/knox/gateway/service/knoxsso/WebSSOResourceTest.java
#   
gateway-service-knoxtoken/src/test/java/org/apache/knox/gateway/service/knoxtoken/TokenServiceResourceTest.java


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/416ee7c1
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/416ee7c1
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/416ee7c1

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: 416ee7c15076ddcaf25cd6a908e6cf1b39683673
Parents: f4a4355 2666894
Author: Sandeep More 
Authored: Wed Sep 20 09:52:47 2017 -0400
Committer: Sandeep More 
Committed: Wed Sep 20 09:52:47 2017 -0400

--
 .../federation/AbstractJWTFilterTest.java   |  14 +-
 .../federation/JWTFederationFilterTest.java |   1 -
 .../federation/SSOCookieProviderTest.java   |   1 -
 gateway-service-knoxsso/pom.xml |  11 +-
 .../gateway/service/knoxsso/WebSSOResource.java |  20 +-
 .../service/knoxsso/WebSSOResourceTest.java | 303 +++-
 gateway-service-knoxtoken/pom.xml   |  29 +-
 .../service/knoxtoken/TokenResource.java|  31 +-
 .../knoxtoken/TokenServiceResourceTest.java | 257 +-
 .../gateway/AmbariServiceDefinitionTest.java|  14 +-
 .../knox/gateway/GatewayAdminFuncTest.java  |   2 +-
 .../gateway/GatewayAdminTopologyFuncTest.java   |  62 ++--
 .../apache/knox/gateway/GatewayAppFuncTest.java |  70 ++--
 .../knox/gateway/GatewayBasicFuncTest.java  | 349 +--
 .../knox/gateway/GatewayDeployFuncTest.java |   2 +-
 .../knox/gateway/GatewayHealthFuncTest.java |   6 +-
 .../GatewayLdapDynamicGroupFuncTest.java|   6 +-
 .../knox/gateway/GatewayLdapGroupFuncTest.java  |   4 +-
 .../gateway/GatewayLdapPosixGroupFuncTest.java  |  13 +-
 .../gateway/GatewayLocalServiceFuncTest.java|   2 +-
 .../knox/gateway/GatewayMultiFuncTest.java  |  26 +-
 .../GatewayPortMappingDisableFeatureTest.java   |   4 +-
 .../gateway/GatewayPortMappingFailTest.java |   2 +-
 .../gateway/GatewayPortMappingFuncTest.java |   4 +-
 .../knox/gateway/GatewaySampleFuncTest.java |   2 +-
 .../apache/knox/gateway/Knox242FuncTest.java|   6 +-
 .../apache/knox/gateway/WebHdfsHaFuncTest.java  |  30 +-
 27 files changed, 895 insertions(+), 376 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/416ee7c1/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/AbstractJWTFilterTest.java
--
diff --cc 
gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/AbstractJWTFilterTest.java
index 10efeb5,000..ea56486
mode 100644,00..100644
--- 
a/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/AbstractJWTFilterTest.java
+++ 
b/gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/AbstractJWTFilterTest.java
@@@ -1,636 -1,0 +1,636 @@@
 +/**
 + * 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 org.apache.knox.gateway.provider.federation;
 +
 +import static org.junit.Assert.fail;
 +
 +import java.io.IOException;
 +import java.net.InetAddress;
 +import java.security.AccessController;
 +import java.security.KeyPair;
 +import java.security.KeyPairGenerator;
 +import java.security.NoSuchAlgorithmException;
 +import java.security.Principal;
 +import java.security.PublicKey;
 +import java.security.cert.Certificate;
 +import java.security.interfaces.RSAPrivateKey;
 +import java.security.interfaces.RSAPublicKey;
 +import java.text.MessageFormat;
 +import java.util.Enumeration;
 +import java.util.List;
 +import java.util.ArrayList;
 +import java.util.Properties;
 +import java.util.Date;
 +import java.util.Set;
 +
 +import javax.security.auth.Subject;
 +import javax.servlet.FilterChain;
 +

[05/12] knox git commit: KNOX-1042 - Fix test timeout (Phil Zampino via Sandeep More)

2017-09-20 Thread more
KNOX-1042 - Fix test timeout (Phil Zampino via Sandeep More)


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/a5a88258
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/a5a88258
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/a5a88258

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: a5a88258b82d8451710d048eba94a39cbd4da343
Parents: 3557612
Author: Sandeep More 
Authored: Tue Sep 19 14:12:08 2017 -0400
Committer: Sandeep More 
Committed: Tue Sep 19 14:12:08 2017 -0400

--
 .../test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java| 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/a5a88258/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
--
diff --git 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
index b65575e..c365fb0 100644
--- 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
+++ 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAppFuncTest.java
@@ -548,7 +548,7 @@ public class GatewayAppFuncTest {
 LOG_EXIT();
   }
 
-  @Test( timeout = TestUtils.MEDIUM_TIMEOUT )
+  @Test( timeout = TestUtils.LONG_TIMEOUT )
   public void testDefaultTopology() throws Exception {
 LOG_ENTER();
 



[10/12] knox git commit: Merge remote-tracking branch 'origin/master' into KNOX-998-Package_Restructuring

2017-09-20 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/416ee7c1/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java
--
diff --cc 
gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java
index 859d34d,000..a282cfe
mode 100644,00..100644
--- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java
@@@ -1,672 -1,0 +1,672 @@@
 +/**
 + * 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 org.apache.knox.gateway;
 +
 +import java.io.File;
 +import java.net.URL;
 +import java.nio.charset.Charset;
 +import java.util.ArrayList;
 +import java.util.Collection;
 +import java.util.Enumeration;
 +import java.util.HashMap;
 +import java.util.List;
 +import java.util.Map;
 +import java.util.Properties;
 +import java.util.UUID;
 +
 +import org.apache.commons.io.FileUtils;
 +import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 +import org.apache.knox.gateway.security.ldap.SimpleLdapDirectoryServer;
 +import org.apache.knox.gateway.services.DefaultGatewayServices;
 +import org.apache.knox.gateway.services.GatewayServices;
 +import org.apache.knox.gateway.services.ServiceLifecycleException;
 +import org.apache.knox.gateway.services.topology.TopologyService;
 +import org.apache.hadoop.test.TestUtils;
 +import org.apache.hadoop.test.mock.MockServer;
 +import org.apache.http.HttpStatus;
 +import org.apache.log4j.Appender;
 +import org.hamcrest.MatcherAssert;
 +import org.junit.After;
 +import org.junit.AfterClass;
 +import org.junit.BeforeClass;
 +import org.junit.Test;
 +import org.slf4j.Logger;
 +import org.slf4j.LoggerFactory;
 +
 +import static io.restassured.RestAssured.given;
 +import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
 +import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
 +import static org.hamcrest.CoreMatchers.equalTo;
 +import static org.hamcrest.CoreMatchers.notNullValue;
 +import static org.hamcrest.Matchers.arrayWithSize;
 +import static org.hamcrest.Matchers.hasItemInArray;
 +import static org.hamcrest.core.Is.is;
 +import static org.hamcrest.core.IsNot.not;
 +import static org.junit.Assert.assertThat;
 +import static org.xmlmatchers.transform.XmlConverters.the;
 +import static org.xmlmatchers.xpath.HasXPath.hasXPath;
 +import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
 +
 +public class GatewayAppFuncTest {
 +
 +  private static Logger LOG = LoggerFactory.getLogger( 
GatewayAppFuncTest.class );
 +  private static Class DAT = GatewayAppFuncTest.class;
 +
 +  private static Enumeration appenders;
 +  private static GatewayTestConfig config;
 +  private static DefaultGatewayServices services;
 +  private static GatewayServer gateway;
 +  private static int gatewayPort;
 +  private static String gatewayUrl;
 +  private static String clusterUrl;
 +  private static Properties params;
 +  private static TopologyService topos;
 +  private static MockServer mockWebHdfs;
 +  private static GatewayTestDriver driver = new GatewayTestDriver();
 +
 +  @BeforeClass
 +  public static void setupSuite() throws Exception {
 +LOG_ENTER();
 +//appenders = NoOpAppender.setUp();
 +driver.setupLdap(0);
 +setupGateway();
 +LOG_EXIT();
 +  }
 +
 +  @AfterClass
 +  public static void cleanupSuite() throws Exception {
 +LOG_ENTER();
 +gateway.stop();
 +driver.cleanup();
 +FileUtils.deleteQuietly( new File( config.getGatewayHomeDir() ) );
 +//NoOpAppender.tearDown( appenders );
 +LOG_EXIT();
 +  }
 +
 +  @After
 +  public void cleanupTest() throws Exception {
 +FileUtils.cleanDirectory( new File( config.getGatewayTopologyDir() ) );
 +// Test run should not fail if deleting deployment files is not 
successful.
 +// Deletion has been already done by TopologyService.
 +FileUtils.deleteQuietly( new File( config.getGatewayDeploymentDir() ) );
 +  }
 +
 +  public static void setupGateway() throws Exception {
 +
 +File targetDir = new File( System.getProperty( "user.dir" ), "target" );
 +File gatewayDir = new File( targetDir, "gateway-home-"

[01/12] knox git commit: KNOX-1038 - Replace deprecated rest-assured "content" call with "body"

2017-09-20 Thread more
Repository: knox
Updated Branches:
  refs/heads/KNOX-998-Package_Restructuring f4a4355d4 -> 416ee7c15


KNOX-1038 - Replace deprecated rest-assured "content" call with "body"


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/aac2054c
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/aac2054c
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/aac2054c

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: aac2054c83399669a7084dbb8452013f7e3b532c
Parents: e2e1251
Author: Colm O hEigeartaigh 
Authored: Thu Sep 14 10:12:58 2017 +0100
Committer: Colm O hEigeartaigh 
Committed: Thu Sep 14 10:12:58 2017 +0100

--
 .../gateway/GatewayAdminTopologyFuncTest.java   |   2 -
 .../hadoop/gateway/GatewayBasicFuncTest.java| 125 +--
 .../hadoop/gateway/GatewayHealthFuncTest.java   |   2 +-
 .../GatewayLdapDynamicGroupFuncTest.java|   2 +-
 .../gateway/GatewayLdapPosixGroupFuncTest.java  |   9 --
 .../GatewayPortMappingDisableFeatureTest.java   |   2 +-
 .../gateway/GatewayPortMappingFuncTest.java |   2 +-
 .../apache/hadoop/gateway/Knox242FuncTest.java  |   2 +-
 .../hadoop/gateway/WebHdfsHaFuncTest.java   |  10 +-
 9 files changed, 69 insertions(+), 87 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/aac2054c/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
--
diff --git 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
index 3a5cd84..2efddff 100644
--- 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
+++ 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
@@ -795,6 +795,4 @@ public class GatewayAdminTopologyFuncTest {
 LOG_EXIT();
   }
 
-  private static final String CLASS = 
GatewayAdminTopologyFuncTest.class.getCanonicalName();
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/aac2054c/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
--
diff --git 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
index cbe12a8..472270c 100644
--- 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
+++ 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
@@ -314,7 +314,7 @@ public class GatewayBasicFuncTest {
 //.log().all()
 .statusCode( HttpStatus.SC_OK )
 .contentType( "application/json" )
-.content( "boolean", is( true ) )
+.body( "boolean", is( true ) )
 .when().put( driver.getUrl( "WEBHDFS" ) + "/v1" + root + "/dir" 
).getDetailedCookie( "JSESSIONID" );
 assertThat( cookie.isSecured(), is( true ) );
 assertThat( cookie.isHttpOnly(), is( true ) );
@@ -373,9 +373,6 @@ public class GatewayBasicFuncTest {
 String root = "/tmp/GatewayBasicFuncTest/testBasicOutboundHeaderUseCase";
 String username = "hdfs";
 String password = "hdfs-password";
-InetSocketAddress gatewayAddress = driver.gateway.getAddresses()[0];
-String gatewayHostName = gatewayAddress.getHostName();
-String gatewayAddrName = 
InetAddress.getByName(gatewayHostName).getHostAddress();
 
 driver.getMock( "WEBHDFS" )
 .expect()
@@ -412,7 +409,6 @@ public class GatewayBasicFuncTest {
 String root = "/tmp/GatewayBasicFuncTest/testHdfsTildeUseCase";
 String username = "hdfs";
 String password = "hdfs-password";
-InetSocketAddress gatewayAddress = driver.gateway.getAddresses()[0];
 
 // Attempt to delete the test directory in case a previous run failed.
 // Ignore any result.
@@ -462,7 +458,7 @@ public class GatewayBasicFuncTest {
   //.log().all();
   .statusCode( HttpStatus.SC_OK )
   .contentType( "application/json" )
-  .content( "boolean", is( true ) )
+  .body( "boolean", is( true ) )
   .when().put( driver.getUrl( "WEBHDFS" ) + "/v1/~/dir" );
   driver.assertComplete();
 } finally {
@@ -535,7 +531,7 @@ public class GatewayBasicFuncTest {
 //.log().all();
 .statusCode( HttpStatus.SC_OK )
 .contentType( "application/json" )
-.content( "boolean", is( true ) )
+.body( "boolean", is( true ) )
 .when().put( driver.getUrl( "WEBHDFS" ) + "/v1" + root + "/dir" );
 driver.assertComplete();
 
@@ -557,7 +553,7 @@ public class GatewayBasicFuncTest {
 .expect()
 //.log().ifError()
 .status

[07/12] knox git commit: Merge remote-tracking branch 'origin/master' into KNOX-998-Package_Restructuring

2017-09-20 Thread more
http://git-wip-us.apache.org/repos/asf/knox/blob/416ee7c1/gateway-test/src/test/java/org/apache/knox/gateway/GatewayPortMappingDisableFeatureTest.java
--
diff --cc 
gateway-test/src/test/java/org/apache/knox/gateway/GatewayPortMappingDisableFeatureTest.java
index db1dbe0,000..a4d8166
mode 100644,00..100644
--- 
a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayPortMappingDisableFeatureTest.java
+++ 
b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayPortMappingDisableFeatureTest.java
@@@ -1,252 -1,0 +1,252 @@@
 +package org.apache.knox.gateway;
 +
 +/**
 + * 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.
 + */
 +
 +import com.mycila.xmltool.XMLDoc;
 +import com.mycila.xmltool.XMLTag;
 +import org.apache.hadoop.test.TestUtils;
 +import org.apache.hadoop.test.category.ReleaseTest;
 +import org.apache.hadoop.test.mock.MockServer;
 +import org.apache.http.HttpStatus;
 +import org.junit.After;
 +import org.junit.Before;
 +import org.junit.Rule;
 +import org.junit.Test;
 +import org.junit.experimental.categories.Category;
 +import org.junit.rules.ExpectedException;
 +
 +import java.io.IOException;
 +import java.net.ConnectException;
 +import java.util.concurrent.ConcurrentHashMap;
 +
 +import static io.restassured.RestAssured.given;
 +import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
 +import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
 +import static org.hamcrest.CoreMatchers.is;
 +
 +/**
 + * Test that the Gateway Topology Port Mapping feature is disabled properly.
 + *
 + */
 +@Category(ReleaseTest.class)
 +public class GatewayPortMappingDisableFeatureTest {
 +
 +  // Specifies if the test requests should go through the gateway or directly 
to the services.
 +  // This is frequently used to verify the behavior of the test both with and 
without the gateway.
 +  private static final boolean USE_GATEWAY = true;
 +
 +  // Specifies if the test requests should be sent to mock services or the 
real services.
 +  // This is frequently used to verify the behavior of the test both with and 
without mock services.
 +  private static final boolean USE_MOCK_SERVICES = true;
 +
 +  private static GatewayTestDriver driver = new GatewayTestDriver();
 +
 +  private static MockServer masterServer;
 +
 +  private int eeriePort;
 +
 +  @Rule
 +  public ExpectedException exception = ExpectedException.none();
 +
 +
 +  public GatewayPortMappingDisableFeatureTest() {
 +super();
 +  }
 +
 +  /**
 +   * Creates a deployment of a gateway instance that all test methods will 
share.  This method also creates a
 +   * registry of sorts for all of the services that will be used by the test 
methods.
 +   * The createTopology method is used to create the topology file that would 
normally be read from disk.
 +   * The driver.setupGateway invocation is where the creation of GATEWAY_HOME 
occurs.
 +   * 
 +   * This would normally be done once for this suite but the failure tests 
start affecting each other depending
 +   * on the state the last 'active' url
 +   *
 +   * @throws Exception Thrown if any failure occurs.
 +   */
 +  @Before
 +  public void setup() throws Exception {
 +LOG_ENTER();
 +
 +eeriePort = getAvailablePort(1240, 49151);
 +
 +ConcurrentHashMap topologyPortMapping = new 
ConcurrentHashMap();
 +topologyPortMapping.put("eerie", eeriePort);
 +
 +masterServer = new MockServer("master", true);
 +GatewayTestConfig config = new GatewayTestConfig();
 +config.setGatewayPath("gateway");
 +config.setTopologyPortMapping(topologyPortMapping);
 +// disable the feature
 +config.setGatewayPortMappingEnabled(false);
 +
 +driver.setResourceBase(WebHdfsHaFuncTest.class);
 +driver.setupLdap(0);
 +
 +driver.setupService("WEBHDFS", "http://vm.local:50070/webhdfs";, 
"/eerie/webhdfs", USE_MOCK_SERVICES);
 +
 +driver.setupGateway(config, "eerie", createTopology("WEBHDFS"), 
USE_GATEWAY);
 +
 +LOG_EXIT();
 +  }
 +
 +  @After
 +  public void cleanup() throws Exception {
 +LOG_ENTER();
 +driver.cleanup();
 +driver.reset();
 +masterServer.reset();
 +LOG_EXIT();
 +  }
 +
 +  /**
 +   * Test the sta

knox git commit: KNOX-1052 - Add some tests for the Knox SSO Service

2017-09-20 Thread coheigea
Repository: knox
Updated Branches:
  refs/heads/master a5a88258b -> 2666894bc


KNOX-1052 - Add some tests for the Knox SSO Service


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/2666894b
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/2666894b
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/2666894b

Branch: refs/heads/master
Commit: 2666894bc84281ed78890110ab15b009fa5f2830
Parents: a5a8825
Author: Colm O hEigeartaigh 
Authored: Wed Sep 20 11:09:54 2017 +0100
Committer: Colm O hEigeartaigh 
Committed: Wed Sep 20 11:09:54 2017 +0100

--
 gateway-service-knoxsso/pom.xml |  11 +-
 .../gateway/service/knoxsso/WebSSOResource.java |  20 +-
 .../service/knoxsso/WebSSOResourceTest.java | 304 ++-
 3 files changed, 308 insertions(+), 27 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/knox/blob/2666894b/gateway-service-knoxsso/pom.xml
--
diff --git a/gateway-service-knoxsso/pom.xml b/gateway-service-knoxsso/pom.xml
index f5018a2..e6b6ca5 100644
--- a/gateway-service-knoxsso/pom.xml
+++ b/gateway-service-knoxsso/pom.xml
@@ -59,9 +59,10 @@
   gateway-test-utils
   test
 
-  
-  org.easymock
-  easymock
-  test
-
+
+  org.easymock
+  easymock
+  test
+
+  
 

http://git-wip-us.apache.org/repos/asf/knox/blob/2666894b/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
--
diff --git 
a/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
 
b/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
index 7cc5378..0d9e6dd 100644
--- 
a/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
+++ 
b/gateway-service-knoxsso/src/main/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResource.java
@@ -23,6 +23,7 @@ import java.net.URISyntaxException;
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -74,14 +75,14 @@ public class WebSSOResource {
   private long tokenTTL = 3l;
   private String whitelist = null;
   private String domainSuffix = null;
-  private String[] targetAudiences = null;
+  private List targetAudiences = new ArrayList<>();
   private boolean enableSession = false;
 
   @Context
-  private HttpServletRequest request;
+  HttpServletRequest request;
 
   @Context
-  private HttpServletResponse response;
+  HttpServletResponse response;
 
   @Context
   ServletContext context;
@@ -124,7 +125,10 @@ public class WebSSOResource {
 
 String audiences = 
context.getInitParameter(SSO_COOKIE_TOKEN_AUDIENCES_PARAM);
 if (audiences != null) {
-  targetAudiences = audiences.split(",");
+  String[] auds = audiences.split(",");
+  for (int i = 0; i < auds.length; i++) {
+targetAudiences.add(auds[i]);
+  }
 }
 
 String ttl = context.getInitParameter(SSO_COOKIE_TOKEN_TTL_PARAM);
@@ -180,14 +184,10 @@ public class WebSSOResource {
 
 try {
   JWT token = null;
-  if (targetAudiences == null || targetAudiences.length == 0) {
+  if (targetAudiences.isEmpty()) {
 token = ts.issueToken(p, "RS256", getExpiry());
   } else {
-ArrayList aud = new ArrayList();
-for (int i = 0; i < targetAudiences.length; i++) {
-  aud.add(targetAudiences[i]);
-}
-token = ts.issueToken(p, aud, "RS256", getExpiry());
+token = ts.issueToken(p, targetAudiences, "RS256", getExpiry());
   }
 
   // Coverity CID 1327959

http://git-wip-us.apache.org/repos/asf/knox/blob/2666894b/gateway-service-knoxsso/src/test/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResourceTest.java
--
diff --git 
a/gateway-service-knoxsso/src/test/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResourceTest.java
 
b/gateway-service-knoxsso/src/test/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResourceTest.java
index 73910dd..c953c91 100644
--- 
a/gateway-service-knoxsso/src/test/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResourceTest.java
+++ 
b/gateway-service-knoxsso/src/test/java/org/apache/hadoop/gateway/service/knoxsso/WebSSOResourceTest.java
@@ -17,15 +17,65 @@
  */
 package org.apache.hadoop.gateway.service.knoxsso;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.security.KeyPair;
+import