Skip to content

Commit

Permalink
Unit tests for result of ticket validation with subject
Browse files Browse the repository at this point in the history
  • Loading branch information
sterowney committed Nov 7, 2018
1 parent e98d33a commit bf6ccb2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public KerberosTicketValidation(String username, String servicePrincipal, byte[]
}

public KerberosTicketValidation(String username, Subject subject, byte[] responseToken, GSSContext gssContext) {
this(username, subject, responseToken, gssContext, null)
this(username, subject, responseToken, gssContext, null);
}

public KerberosTicketValidation(String username, Subject subject, byte[] responseToken, GSSContext gssContext, GSSCredential delegationCredential) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public LoginConfig(String keyTabLocation, String servicePrincipalName, String re
this.realmName = realmName;
this.multiTier = multiTier;
this.debug = debug;
this.refreshKrb5Config = refreshKrb5Configx
this.refreshKrb5Config = refreshKrb5Config;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.springframework.security.kerberos.authentication;

import org.ietf.jgss.GSSContext;
import org.ietf.jgss.GSSCredential;
import org.junit.Test;

import javax.security.auth.Subject;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class KerberosTicketValidationTest {

private String username = "username";
private Subject subject = new Subject();
private byte[] responseToken = "token".getBytes();
private GSSContext gssContext = mock(GSSContext.class);
private GSSCredential delegationCredential = mock(GSSCredential.class);

@Test
public void createResultOfTicketValidationWithSubject() {

KerberosTicketValidation ticketValidation = new KerberosTicketValidation(
username,
subject,
responseToken,
gssContext);

assertEquals(username, ticketValidation.username());
assertEquals(responseToken, ticketValidation.responseToken());
assertEquals(gssContext, ticketValidation.getGssContext());

assertNull("With no credential delegation", ticketValidation.getDelegationCredential());
}

@Test
public void createResultOfTicketValidationWithSubjectAndDelegation() {

KerberosTicketValidation ticketValidation = new KerberosTicketValidation(
username,
subject,
responseToken,
gssContext,
delegationCredential);

assertEquals(username, ticketValidation.username());
assertEquals(responseToken, ticketValidation.responseToken());
assertEquals(gssContext, ticketValidation.getGssContext());

assertEquals("With no credential delegation", delegationCredential, ticketValidation.getDelegationCredential());
}
}

0 comments on commit bf6ccb2

Please sign in to comment.