Skip to content

Commit

Permalink
JAVACLIENT-143: Fix IllegalArgumentException base64 of login:password…
Browse files Browse the repository at this point in the history
… is longer than 75
  • Loading branch information
julien-brotons authored and kevinleturc committed Nov 28, 2017
1 parent bae86de commit 4f78225
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
package org.nuxeo.client;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.Test;
import org.nuxeo.client.objects.user.User;
import org.nuxeo.client.objects.user.UserManager;
import org.nuxeo.client.spi.NuxeoClientRemoteException;

/**
Expand Down Expand Up @@ -72,4 +74,24 @@ public void itCanChangeAuthMethod() {
assertEquals("Administrator", currentUser.getUserName());
}

@Test
public void itCanLoginWithLongCredentials() {
UserManager userManager = ITBase.createClientBuilder().connect().userManager();

String email = "[email protected]";
String password = "verylongpassword0123456789";
// first create user
User user = new User();
user.setUserName(email);
user.setEmail(email);
user.setPassword(password);
userManager.createUser(user);
// now test
User currentUser = ITBase.createClient(email, password).getCurrentUser();
assertEquals(email, currentUser.getUserName());
assertFalse(currentUser.isAdministrator());
// delete it
userManager.deleteUser(email);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public BasicAuthInterceptor(String username, String password) {
throw new NuxeoClientException("'username' and 'password' must be set");
}
String info = username + ":" + password;
token = "Basic " + Base64.encode(info);
token = "Basic " + Base64.encode(info, Base64.DONT_BREAK_LINES);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ public static String encode(String content) {
return encodeBytes(content.getBytes());
}

/**
* @param options encoding options provided by {@link Base64}.
* @since 3.0.
* @see Base64#DONT_BREAK_LINES
*/
public static String encode(String content, int options) {
return encodeBytes(content.getBytes(), options);
}

public static String encode(String content, String charset) throws UnsupportedEncodingException {
return encodeBytes(content.getBytes(charset));
}
Expand Down

0 comments on commit 4f78225

Please sign in to comment.