Skip to content

Commit

Permalink
Merge pull request #264 from hazendaz/master
Browse files Browse the repository at this point in the history
Jmockit and other enhancements
  • Loading branch information
hazendaz committed Oct 18, 2015
2 parents 286036a + 1da5ae4 commit 3e05b8b
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 128 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ addons:
description: Build submitted via Travis CI
notification_email: [email protected]
build_command_prepend: mvn clean
build_command: mvn -DskipTests=true install
build_command: mvn clean install -DskipTests
branch_pattern: coverity_scan

before_script:
- cd Source/JNA

script: if [ ${COVERITY_SCAN_BRANCH} != 1 ]; then mvn clean install -DskipTests=true; fi
script: if [ ${COVERITY_SCAN_BRANCH} != 1 ]; then mvn clean install -DskipTests; fi

after_success:
- chmod -R 777 ../../travis/after_success.sh
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ Essentials
* [Older Versions on CodePlex](http://waffle.codeplex.com/).
* [PlatformSDK Security Group](https://groups.google.com/group/microsoft.public.platformsdk.security)

Jetty
-----
Jetty support is build using java 7 like everything else. However, using the provided jetty version will require java 8 usage.
To continue with java 7, drop back to Jetty version 9.2.13.v20150730.

Legacy 1.7.x Branch
-------------------
Waffle legacy support. From 1/3/2015 through 1/1/2016 we will continue to support the 1.7.x branch for any bug fixes to
Expand Down
14 changes: 0 additions & 14 deletions Source/JNA/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
<contiperf.version>2.3.4</contiperf.version>
<jmockit.version>1.19</jmockit.version>
<junit.version>4.12</junit.version>
<mockito.version>1.10.19</mockito.version>
<slf4j.version>1.7.12</slf4j.version>

<signature.artifact>java17</signature.artifact>
Expand Down Expand Up @@ -152,19 +151,6 @@
<version>${jmockit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- Use mockito core as mockito all uses old version of hamcrest -->
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion Source/JNA/waffle-jetty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<el.version>3.0.1-b08</el.version>
<el-api.version>3.0.1-b04</el-api.version>
<jetty.version>9.3.4.v20151007</jetty.version>
<jetty.version>9.3.5.v20151012</jetty.version>
<jdt.version>4.4.2</jdt.version>
<jsp.version>2.3.3-b02</jsp.version>
<jsp-api.version>2.3.2-b01</jsp-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public static void main(final String[] args) throws Exception {
try {
StartEmbeddedJetty.LOGGER.info(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
server.start();
System.in.read();
if (System.in.read() == -1) {
StartEmbeddedJetty.LOGGER.error("End of Stream reached");
return;
}
StartEmbeddedJetty.LOGGER.info(">>> STOPPING EMBEDDED JETTY SERVER");
server.stop();
server.join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import javax.security.auth.login.LoginException;

import mockit.Deencapsulation;
import mockit.Expectations;
import mockit.Mocked;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mockito;

import waffle.windows.auth.PrincipalFormat;

Expand All @@ -49,7 +49,8 @@ public class WindowsLoginModuleTest {
private Subject subject;

/** The callback handler. */
private CallbackHandler callbackHandler;
@Mocked
CallbackHandler callbackHandler;

/** The options. */
private Map<String, String> options;
Expand Down Expand Up @@ -136,7 +137,6 @@ public void commit_withDebug() throws LoginException {
public void init() {
this.loginModule = new WindowsLoginModule();
this.subject = new Subject();
this.callbackHandler = Mockito.mock(CallbackHandler.class);
this.options = new HashMap<>();
}

Expand Down Expand Up @@ -200,7 +200,12 @@ public void login_throwIOException() throws LoginException, IOException, Unsuppo
this.options.put("debug", "true");
this.loginModule.initialize(this.subject, this.callbackHandler, null, this.options);
Assert.assertTrue(this.loginModule.isAllowGuestLogin());
Mockito.doThrow(new IOException()).when(this.callbackHandler).handle(Matchers.any(Callback[].class));
Assert.assertNotNull(new Expectations() {
{
WindowsLoginModuleTest.this.callbackHandler.handle(this.withInstanceOf(Callback[].class));
this.result = new IOException();
}
});
this.loginModule.login();
}

Expand All @@ -220,8 +225,12 @@ public void login_throwUnsupportedCallbackException() throws LoginException, IOE
this.options.put("debug", "true");
this.loginModule.initialize(this.subject, this.callbackHandler, null, this.options);
Assert.assertTrue(this.loginModule.isAllowGuestLogin());
Mockito.doThrow(new UnsupportedCallbackException(new NameCallback("Callback Exception")))
.when(this.callbackHandler).handle(Matchers.any(Callback[].class));
Assert.assertNotNull(new Expectations() {
{
WindowsLoginModuleTest.this.callbackHandler.handle(this.withInstanceOf(Callback[].class));
this.result = new UnsupportedCallbackException(new NameCallback("Callback Exception"));
}
});
this.loginModule.login();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import mockit.Expectations;
import mockit.Mocked;
import waffle.windows.auth.IWindowsAccount;
import waffle.windows.auth.IWindowsIdentity;

Expand All @@ -30,15 +31,25 @@ public class WindowsPrincipalTest {
/** The Constant TEST_FQN. */
private static final String TEST_FQN = "ACME\\john.smith";

/** The windows identity. */
@Mocked
IWindowsIdentity windowsIdentity;

/**
* Test to string.
*/
@Test
public void testToString() {
final IWindowsIdentity windowsIdentity = Mockito.mock(IWindowsIdentity.class);
Mockito.when(windowsIdentity.getFqn()).thenReturn(WindowsPrincipalTest.TEST_FQN);
Mockito.when(windowsIdentity.getGroups()).thenReturn(new IWindowsAccount[0]);
final WindowsPrincipal principal = new WindowsPrincipal(windowsIdentity);
Assert.assertNotNull(new Expectations() {
{
WindowsPrincipalTest.this.windowsIdentity.getFqn();
this.result = WindowsPrincipalTest.TEST_FQN;
WindowsPrincipalTest.this.windowsIdentity.getGroups();
this.result = new IWindowsAccount[0];

}
});
final WindowsPrincipal principal = new WindowsPrincipal(this.windowsIdentity);
Assert.assertEquals(WindowsPrincipalTest.TEST_FQN, principal.getName());
Assert.assertEquals(WindowsPrincipalTest.TEST_FQN, principal.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public boolean onAccessDenied(final ServletRequest request, final ServletRespons
* waffle.shiro.negotiate.NegotiateAuthenticationFilter#onLoginSuccess(org.apache.shiro.authc.AuthenticationToken
* , org.apache.shiro.subject.Subject, javax.servlet.ServletRequest, javax.servlet.ServletResponse)
*/
@SuppressWarnings("synthetic-access")
@Override
protected boolean onLoginSuccess(final AuthenticationToken token, final Subject subject,
final ServletRequest request, final ServletResponse response) throws Exception {
Expand Down Expand Up @@ -178,6 +179,7 @@ public boolean onAccessDenied(final ServletRequest request, final ServletRespons
* AuthenticationToken, org.apache.shiro.subject.Subject, javax.servlet.ServletRequest,
* javax.servlet.ServletResponse)
*/
@SuppressWarnings("synthetic-access")
@Override
protected boolean onLoginSuccess(final AuthenticationToken token, final Subject subject,
final ServletRequest request, final ServletResponse response) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,75 +13,55 @@
*/
package waffle.shiro.dynamic;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletRequest;

import mockit.Deencapsulation;
import mockit.Expectations;
import mockit.Mocked;
import mockit.Tested;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.Mockito;

/**
* The Class DynamicAuthenticationFilterTest.
*
* @author Dan Rollo Date: 2/26/13 Time: 5:47 PM
*/
public class DynamicAuthenticationFilterTest {

/**
* The Class MockServletRequest.
*/
private static abstract class MockServletRequest implements ServletRequest {

/** The parameters. */
private final Map<String, String> parameters = new HashMap<>();

/*
* (non-Javadoc)
* @see javax.servlet.ServletRequest#getParameter(java.lang.String)
*/
@Override
public String getParameter(final String name) {
return this.parameters.get(name);
}

}

/** The dynamic authentication filter. */
private DynamicAuthenticationFilter dynamicAuthenticationFilter;
@Tested
DynamicAuthenticationFilter dynamicAuthenticationFilter;

/** The request. */
private MockServletRequest request;

/**
* Sets the up.
*/
@Before
public void setUp() {
this.dynamicAuthenticationFilter = new DynamicAuthenticationFilter();

this.request = Mockito.mock(MockServletRequest.class, Mockito.CALLS_REAL_METHODS);
Deencapsulation.setField(this.request, new HashMap<String, String>());
}
@Mocked
ServletRequest request;

/**
* Test is auth type negotiate.
*/
@Test
public void testIsAuthTypeNegotiate() {
Mockito.when(this.request.getParameter(Matchers.anyString())).thenReturn(null);
Assert.assertNotNull(new Expectations() {
{
DynamicAuthenticationFilterTest.this.request.getParameter(this.anyString);
this.result = null;
}
});
Assert.assertFalse(this.dynamicAuthenticationFilter.isAuthTypeNegotiate(this.request));

Mockito.when(this.request.getParameter(Matchers.anyString())).thenReturn("zzz");
Assert.assertNotNull(new Expectations() {
{
DynamicAuthenticationFilterTest.this.request.getParameter(this.anyString);
this.result = "zzz";
}
});
Assert.assertFalse(this.dynamicAuthenticationFilter.isAuthTypeNegotiate(this.request));

Mockito.when(this.request.getParameter(Matchers.anyString())).thenReturn(
DynamicAuthenticationFilter.PARAM_VAL_AUTHTYPE_NEGOTIATE);
Assert.assertNotNull(new Expectations() {
{
DynamicAuthenticationFilterTest.this.request.getParameter(this.anyString);
this.result = DynamicAuthenticationFilter.PARAM_VAL_AUTHTYPE_NEGOTIATE;
}
});
Assert.assertTrue(this.dynamicAuthenticationFilter.isAuthTypeNegotiate(this.request));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,49 @@
*/
package waffle.shiro.negotiate;

import junit.framework.TestCase;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import mockit.Expectations;
import mockit.Mocked;
import mockit.Tested;

/**
* The Class NegotiateAuthenticationRealmTest.
*
* @author Dan Rollo Date: 2/14/13 Time: 11:11 PM
*/
public final class NegotiateAuthenticationRealmTest extends TestCase {
public final class NegotiateAuthenticationRealmTest {

/** The neg auth realm. */
@Tested
private NegotiateAuthenticationRealm negAuthRealm;

/*
* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
this.negAuthRealm = new NegotiateAuthenticationRealm();
}

/**
* Test supports.
*/
@Test
public void testSupports() {
TestCase.assertFalse("Non-NegotiateToken should not be supported.",
this.negAuthRealm.supports(new AuthenticationToken() {
private static final long serialVersionUID = 334672725950031145L;
Assert.assertFalse("Non-NegotiateToken should not be supported.",
this.negAuthRealm.supports(Mockito.mock(AuthenticationToken.class, Mockito.CALLS_REAL_METHODS)));

@Override
public Object getPrincipal() {
return null;
}

@Override
public Object getCredentials() {
return null;
}
}));
Assert.assertTrue(this.negAuthRealm.supports(new NegotiateToken(null, null, null, null, false, false, null)));
}

TestCase.assertTrue(this.negAuthRealm.supports(new NegotiateToken(null, null, null, null, false, false, null)));
/**
* Test authentication info exception.
*/
@Test(expected = AuthenticationException.class)
public void testAuthenticationInfo(@Mocked final NegotiateToken negotiateToken) {
Assert.assertNotNull(new Expectations() {
{
negotiateToken.getIn();
this.result = new Byte((byte) 0);
}
});
this.negAuthRealm.doGetAuthenticationInfo(negotiateToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ abstract class WaffleAuthenticatorBase extends AuthenticatorBase {
private static final Set<String> SUPPORTED_PROTOCOLS = new LinkedHashSet<>(Arrays.asList("Negotiate", "NTLM"));

/** The info. */
@SuppressWarnings("hiding")
protected String info;

/** The log. */
Expand Down
Loading

0 comments on commit 3e05b8b

Please sign in to comment.