Extended HttpTransporterTest to cover credential encoding
Project: http://git-wip-us.apache.org/repos/asf/maven-aether/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-aether/commit/d252910f Tree: http://git-wip-us.apache.org/repos/asf/maven-aether/tree/d252910f Diff: http://git-wip-us.apache.org/repos/asf/maven-aether/diff/d252910f Branch: refs/heads/master Commit: d252910f5415c58f7342c5ba357e1c007396279c Parents: 51ea175 Author: Benjamin Bentmann <bentm...@sonatype.com> Authored: Fri Aug 29 16:25:54 2014 +0200 Committer: Benjamin Bentmann <bentm...@sonatype.com> Committed: Fri Aug 29 16:25:54 2014 +0200 ---------------------------------------------------------------------- .../aether/transport/http/HttpServer.java | 14 +++++++--- .../transport/http/HttpTransporterTest.java | 28 +++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-aether/blob/d252910f/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java ---------------------------------------------------------------------- diff --git a/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java b/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java index be97ff1..5fee786 100644 --- a/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java +++ b/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpServer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Sonatype, Inc. + * Copyright (c) 2013, 2014 Sonatype, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -100,6 +100,8 @@ public class HttpServer private Connector httpsConnector; + private String credentialEncoding = StringUtil.__ISO_8859_1; + private String username; private String password; @@ -194,6 +196,12 @@ public class HttpServer return this; } + public HttpServer setCredentialEncoding( String credentialEncoding ) + { + this.credentialEncoding = ( credentialEncoding != null ) ? credentialEncoding : StringUtil.__ISO_8859_1; + return this; + } + public HttpServer setAuthentication( String username, String password ) { this.username = username; @@ -524,7 +532,7 @@ public class HttpServer } - static boolean checkBasicAuth( String credentials, String username, String password ) + boolean checkBasicAuth( String credentials, String username, String password ) { if ( credentials != null ) { @@ -537,7 +545,7 @@ public class HttpServer credentials = credentials.substring( space + 1 ); try { - credentials = B64Code.decode( credentials, StringUtil.__ISO_8859_1 ); + credentials = B64Code.decode( credentials, credentialEncoding ); } catch ( UnsupportedEncodingException e ) { http://git-wip-us.apache.org/repos/asf/maven-aether/blob/d252910f/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java ---------------------------------------------------------------------- diff --git a/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java b/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java index 16fe0c4..8a36861 100644 --- a/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java +++ b/aether-transport-http/src/test/java/org/eclipse/aether/transport/http/HttpTransporterTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Sonatype, Inc. + * Copyright (c) 2013, 2014 Sonatype, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1042,6 +1042,32 @@ public class HttpTransporterTest } @Test + public void testCredentialEncoding_Default() + throws Exception + { + testCredentialEncoding( null ); + } + + @Test + public void testCredentialEncoding_Utf8() + throws Exception + { + testCredentialEncoding( "UTF-8" ); + } + + private void testCredentialEncoding( String encoding ) + throws Exception + { + session.setConfigProperty( ConfigurationProperties.HTTP_CREDENTIAL_ENCODING, encoding ); + String username = "testuser", password = "\u00e4\u00f6\u00fc"; + httpServer.setAuthentication( username, password ); + httpServer.setCredentialEncoding( encoding ); + auth = new AuthenticationBuilder().addUsername( username ).addPassword( password ).build(); + newTransporter( httpServer.getHttpUrl() ); + transporter.get( new GetTask( URI.create( "repo/file.txt" ) ) ); + } + + @Test public void testAuthSchemeReuse() throws Exception {