use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class JMSessionTest method messageID.
@Test
public void messageID() throws Exception {
Provisioning prov = Provisioning.getInstance();
Domain domain = prov.createDomain("example.com", new HashMap<String, Object>());
Account account = prov.createAccount("user1@example.com", "test123", new HashMap<String, Object>());
MimeMessage mm = new MimeMessage(JMSession.getSmtpSession(account));
mm.saveChanges();
Assert.assertEquals("message ID contains account domain", domain.getName() + '>', mm.getMessageID().split("@")[1]);
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class JWTBasedAuthTest method testZimbraQoSFilterExtractUserId.
@Test
public void testZimbraQoSFilterExtractUserId() {
HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
Cookie[] cookies = new Cookie[1];
String salt = "s1";
Cookie cookie = new Cookie("ZM_JWT", salt);
cookie.setHttpOnly(true);
cookies[0] = cookie;
try {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
String jwt = generateJWT(acct, salt);
EasyMock.expect(req.getCookies()).andReturn(cookies);
EasyMock.expectLastCall().times(2);
EasyMock.expect(req.getHeader(Constants.AUTH_HEADER)).andReturn("Bearer " + jwt);
int port = 7071;
EasyMock.expect(req.getLocalPort()).andReturn(port);
EasyMock.replay(req);
String accountId = ZimbraQoSFilter.extractUserId(req);
Assert.assertEquals(acct.getId(), accountId);
} catch (ServiceException | AuthTokenException e) {
e.printStackTrace();
Assert.fail("testZimbraQoSFilterExtractUserId failed");
}
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class JWTBasedAuthTest method testGetJWToken.
@Test
public void testGetJWToken() {
Account acct;
try {
acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
String salt = "s1";
String salts = "s2|s3|s1";
AuthTokenKey atkey = AuthTokenUtil.getCurrentKey();
byte[] jwtKey = Bytes.concat(atkey.getKey(), salt.getBytes());
long issuedAt = System.currentTimeMillis();
long expires = issuedAt + 3600000;
AuthTokenProperties properties = new AuthTokenProperties(acct, true, null, expires, AuthMech.zimbra, Usage.AUTH);
String jwt = JWTUtil.generateJWT(jwtKey, salt, issuedAt, properties, atkey.getVersion());
AuthToken at = ZimbraJWToken.getJWToken(jwt, salts);
Assert.assertEquals(acct.getId(), at.getAccountId());
Assert.assertEquals(Usage.AUTH, at.getUsage());
Assert.assertEquals(expires / 1000, at.getExpires() / 1000);
Assert.assertEquals(AuthMech.zimbra, at.getAuthMech());
Assert.assertEquals(false, at.isAdmin());
} catch (ServiceException | AuthTokenException e) {
e.printStackTrace();
Assert.fail("testGenerateAndValidateJWT failed");
}
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class JWTBasedAuthTest method testUserServletJWTFlowWithJWTQueryParam.
@Test
public void testUserServletJWTFlowWithJWTQueryParam() {
try {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
UserServletContext context = mockServletConext(acct, true);
UserServletUtil.getAccount(context);
Assert.assertNotNull(context.authToken);
Assert.assertEquals(acct.getId(), context.authToken.getAccountId());
} catch (ServiceException | AuthTokenException | IOException | ServletException | UserServletException e1) {
e1.printStackTrace();
Assert.fail("testUserServletJWTFlow failed");
}
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class JWTBasedAuthTest method testAccountAndUsageJWT.
@Test
public void testAccountAndUsageJWT() {
Account acct;
try {
acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
AuthToken at = AuthProvider.getAuthToken(acct, Usage.TWO_FACTOR_AUTH, TokenType.JWT);
validateJWT(at, acct.getId());
} catch (ServiceException e) {
Assert.fail("testAccountAndUsageJWT failed");
}
}
Aggregations