Пример #1
0
 @Test
 public void shouldThrowIfHeadersDoNotContainAPrincipal() throws Exception {
   when(signatureSecurityResult.get(WSSecurityEngineResult.TAG_PRINCIPAL)).thenReturn(null);
   try {
     wsSecurityHandler.processEnvelope(envelope);
     fail("Should have thrown WSSecurityHandlerException");
   } catch (WSSecurityHandlerException e) {
     assertThat(e.getMessage(), containsString("unable to find principal in WS-Security headers"));
   }
 }
Пример #2
0
 @Test
 public void shouldThrowIfSecurityEngineResultsAreNull() throws Exception {
   when(cryptoWrapper.processSecurityHeader(envelope)).thenReturn(null);
   try {
     wsSecurityHandler.processEnvelope(envelope);
     fail("Should have thrown WSSecurityHandlerException");
   } catch (WSSecurityHandlerException e) {
     assertThat(e.getMessage(), containsString("incorrect number of WS-Security headers"));
   }
 }
Пример #3
0
 @Test
 public void shouldThrowIfSecurityEngineResultsDoNotContainSignHeader() throws Exception {
   blankOutResultAtPosition(2);
   try {
     wsSecurityHandler.processEnvelope(envelope);
     fail("Should have thrown WSSecurityHandlerException");
   } catch (WSSecurityHandlerException e) {
     assertThat(e.getMessage(), containsString("missing WS-Security header(s): SIGN"));
   }
 }
Пример #4
0
 @Test
 public void shouldThrowIfSecurityEngineResultsHaveMoreThanThreeResults() throws Exception {
   wsSecurityEngineResults.add(new WSSecurityEngineResult(0, new Object()));
   try {
     wsSecurityHandler.processEnvelope(envelope);
     fail("Should have thrown WSSecurityHandlerException");
   } catch (WSSecurityHandlerException e) {
     assertThat(e.getMessage(), containsString("incorrect number of WS-Security headers"));
   }
 }
Пример #5
0
 @Test
 public void shouldThrowWrappedExceptionFromVerify() throws Exception {
   CertificateException certificateException = new CertificateException();
   doThrow(certificateException).when(requestCertificate).verify(publicKey);
   try {
     wsSecurityHandler.processEnvelope(envelope);
     fail("Should have thrown WSSecurityHandlerException");
   } catch (WSSecurityHandlerException e) {
     assertTrue("should have wrapped certificateException", e.getCause() == certificateException);
   }
 }
Пример #6
0
 @Test
 public void shouldThrowIfCryptoWrapperDoesNotReturnACertificate() throws Exception {
   when(cryptoWrapper.getUserCertificate(USER_ID, requestCertificate)).thenReturn(null);
   try {
     wsSecurityHandler.processEnvelope(envelope);
     fail("Should have thrown WSSecurityHandlerException");
   } catch (WSSecurityHandlerException e) {
     assertThat(
         e.getMessage(), containsString("unable to get user certificate from cryptoWrapper"));
   }
 }
Пример #7
0
 @Test
 public void shouldThrowIfPrincipalNameDoesNotContainAUserId() throws Exception {
   when(principal.getName()).thenReturn("a=b,c=d,e=f");
   try {
     wsSecurityHandler.processEnvelope(envelope);
     fail("Should have thrown WSSecurityHandlerException");
   } catch (WSSecurityHandlerException e) {
     assertThat(
         e.getMessage(),
         containsString("unable to determine userId from principal name 'a=b,c=d,e=f'"));
   }
 }
Пример #8
0
  @Test
  public void shouldThrowExceptionWhenUserIsDisabled() throws Exception {

    when(user.isEnabled()).thenReturn(false);
    try {
      // act
      wsSecurityHandler.processEnvelope(envelope);

      fail("Should have thrown WSSecurityHandlerException");
    } catch (WSSecurityHandlerException e) {

      assertEquals("User null is not enabled", e.getMessage());
    }
  }
Пример #9
0
 @Test
 public void shouldVerifyRequestCertificateAgainstUserPublicKey() throws Exception {
   wsSecurityHandler.processEnvelope(envelope);
   verify(requestCertificate).verify(publicKey);
 }
Пример #10
0
 @Test
 public void shouldProcessSecurityHeader() throws Exception {
   wsSecurityHandler.processEnvelope(envelope);
   verify(cryptoWrapper).processSecurityHeader(envelope);
 }
Пример #11
0
 @Test
 public void principalNameContainingASpaceShouldStillWork() throws Exception {
   when(principal.getName()).thenReturn("a=b,c=d, O=" + USER_ID + ",e=f");
   wsSecurityHandler.processEnvelope(envelope);
 }