@Test @LocalData public void testDescriptorAuthenticate() throws Exception { AuthenticateDescriptorImpl d = new AuthenticateDescriptorImpl(); assertTrue(d.authenticate(new SpecificUsersAuthorizationStrategy("test1", false), "test1")); assertFalse(d.authenticate(new SpecificUsersAuthorizationStrategy("test1", false), "test2")); assertFalse(d.authenticate(new SpecificUsersAuthorizationStrategy("test1", false), "")); assertFalse(d.authenticate(new SpecificUsersAuthorizationStrategy("", false), "test2")); assertFalse(d.authenticate(new SpecificUsersAuthorizationStrategy("test1", false), null)); assertFalse(d.authenticate(new SpecificUsersAuthorizationStrategy(null, false), "test2")); }
@Test public void testDescriptorAuthenticateWithApitoken() throws Exception { prepareSecurity(); String apitokenForTest1 = User.get("test1").getProperty(ApiTokenProperty.class).getApiToken(); AuthenticateDescriptorImpl d = new AuthenticateDescriptorImpl(); assertTrue( d.authenticateWithApitoken( new SpecificUsersAuthorizationStrategy("test1", false), apitokenForTest1)); assertFalse( d.authenticateWithApitoken( new SpecificUsersAuthorizationStrategy("test1", false), apitokenForTest1 + "xxx")); assertFalse( d.authenticateWithApitoken(new SpecificUsersAuthorizationStrategy("test1", false), "")); assertFalse( d.authenticateWithApitoken( new SpecificUsersAuthorizationStrategy("", false), apitokenForTest1)); assertFalse( d.authenticateWithApitoken(new SpecificUsersAuthorizationStrategy("test1", false), null)); assertFalse( d.authenticateWithApitoken( new SpecificUsersAuthorizationStrategy(null, false), apitokenForTest1)); }