Class AbstractDuoActionTest

    • Constructor Detail

      • AbstractDuoActionTest

        public AbstractDuoActionTest()
    • Method Detail

      • createPlainDummyToken

        protected com.nimbusds.jwt.JWT createPlainDummyToken​(@Nonnull
                                                             String authResult,
                                                             @Nonnull
                                                             String authResultMessage,
                                                             @Nonnull
                                                             String aud,
                                                             @Nonnull
                                                             Instant exp,
                                                             @Nonnull
                                                             Instant iat,
                                                             @Nonnull
                                                             Instant authTime,
                                                             @Nonnull
                                                             String apiHost,
                                                             @Nonnull
                                                             String factor)
        Create a dummy Duo plain (no sig or enc) JWT token.
        Parameters:
        authResult - the authentication result e.g. allow.
        authResultMessage - a user friendly result message.
        aud - audience
        exp - expiration time.
        iat - issued at.
        authTime - the auth time.
        apiHost - the api host
        factor - the duo factor
        Returns:
        the duo auth token.
      • createPlainDummyTokenNoAuthResult

        protected com.nimbusds.jwt.JWT createPlainDummyTokenNoAuthResult​(@Nonnull
                                                                         String authResult,
                                                                         @Nonnull
                                                                         String authResultMessage,
                                                                         @Nonnull
                                                                         String aud,
                                                                         @Nonnull
                                                                         Instant exp,
                                                                         @Nonnull
                                                                         Instant iat,
                                                                         @Nonnull
                                                                         Instant authTime,
                                                                         @Nonnull
                                                                         String apiHost,
                                                                         @Nonnull
                                                                         String factor)
        Create a dummy Duo plain (no sig or enc) JWT token with no auth_result.
        Parameters:
        authResult - the authentication result e.g. allow.
        authResultMessage - a user friendly result message.
        aud - audience
        exp - expiration time.
        iat - issued at.
        authTime - the auth time.
        apiHost - the api host
        factor - the duo factor
        Returns:
        the duo auth token.
      • createPlainDummyToken

        protected com.nimbusds.jwt.JWT createPlainDummyToken​(@Nonnull
                                                             String authResult,
                                                             @Nonnull
                                                             String authResultMessage,
                                                             @Nonnull
                                                             Instant iat,
                                                             @Nonnull
                                                             Instant authTime,
                                                             @Nonnull
                                                             String apiHost,
                                                             @Nonnull
                                                             String factor)
        Create a dummy Duo plain (no sig or enc) JWT token which is missing the 'exp' and 'aud' claims.
        Parameters:
        authResult - the authentication result e.g. allow.
        authResultMessage - a user friendly result message.
        iat - issued at.
        authTime - the auth time.
        apiHost - the api host
        factor - the duo factor
        Returns:
        the duo auth token.
      • createPlainDummyToken

        protected com.nimbusds.jwt.JWT createPlainDummyToken​(@Nonnull
                                                             String authResult,
                                                             @Nonnull
                                                             String authResultMessage,
                                                             @Nonnull
                                                             String aud,
                                                             @Nonnull
                                                             Instant exp,
                                                             @Nonnull
                                                             Instant iat,
                                                             @Nonnull
                                                             Instant authTime,
                                                             @Nonnull
                                                             Instant nbf,
                                                             @Nonnull
                                                             String apiHost,
                                                             @Nonnull
                                                             String factor)
        Create a dummy Duo plain (no sig or enc) JWT token.
        Parameters:
        authResult - the authentication result e.g. allow.
        authResultMessage - a user friendly result message.
        aud - audience
        exp - expiration time.
        iat - issued at.
        authTime - the auth time.
        nbf - not before time.
        apiHost - the api host
        factor - the duo factor
        Returns:
        the duo auth token.
      • createSignedDummyToken

        protected com.nimbusds.jwt.JWT createSignedDummyToken​(@Nonnull
                                                              String headerJson,
                                                              @Nonnull
                                                              String secret,
                                                              @Nonnull
                                                              String authResult,
                                                              @Nonnull
                                                              String authResultMessage,
                                                              @Nonnull
                                                              String aud,
                                                              @Nonnull
                                                              Instant exp,
                                                              @Nonnull
                                                              Instant iat,
                                                              @Nonnull
                                                              Instant authTime,
                                                              @Nonnull
                                                              String apiHost,
                                                              @Nonnull
                                                              String factor)
        Create a signed Duo JWT token.
        Parameters:
        headerJson - the header that defines the crypto params.
        secret - the secret used to sign the JWT.
        authResult - the authentication result e.g. allow.
        authResultMessage - a user friendly result message.
        aud - audience
        exp - expiration time.
        iat - issued at.
        authTime - the auth time.
        apiHost - the api hostname.
        factor - the duo factor.
        Returns:
        the duo auth token.
      • createSignedDummyTokenFromGivenSignature

        protected com.nimbusds.jwt.JWT createSignedDummyTokenFromGivenSignature​(@Nonnull
                                                                                String headerJson,
                                                                                @Nonnull
                                                                                String signatureBase64,
                                                                                @Nonnull
                                                                                String authResult,
                                                                                @Nonnull
                                                                                String authResultMessage,
                                                                                @Nonnull
                                                                                String aud,
                                                                                @Nonnull
                                                                                Instant exp,
                                                                                @Nonnull
                                                                                Instant iat,
                                                                                @Nonnull
                                                                                Instant authTime,
                                                                                @Nonnull
                                                                                String apiHost,
                                                                                @Nonnull
                                                                                String factor)
        Create a signed Duo JWT token using the supplied (not computed) signature. Can be used to generate a token with an invalid signature.
        Parameters:
        headerJson - the header that defines the crypto params.
        signatureBase64 - the base64 encoded signature.
        authResult - the authentication result e.g. allow.
        authResultMessage - a user friendly result message.
        aud - audience
        exp - expiration time.
        iat - issued at.
        authTime - the auth time.
        apiHost - the api hostname.
        factor - the duo factor.
        Returns:
        the duo auth token.
      • createUnsignedSignedDummyToken

        protected com.nimbusds.jwt.JWT createUnsignedSignedDummyToken​(@Nonnull
                                                                      String headerJson,
                                                                      @Nonnull
                                                                      String authResult,
                                                                      @Nonnull
                                                                      String authResultMessage,
                                                                      @Nonnull
                                                                      String aud,
                                                                      @Nonnull
                                                                      Instant exp,
                                                                      @Nonnull
                                                                      Instant iat,
                                                                      @Nonnull
                                                                      Instant authTime,
                                                                      @Nonnull
                                                                      String apiHost,
                                                                      @Nonnull
                                                                      String factor)
        Create a signed Duo JWT token which is NOT signed. Allows testing of unsupported algorithms.
        Parameters:
        headerJson - the header that defines the crypto params.
        authResult - the authentication result e.g. allow.
        authResultMessage - a user friendly result message.
        aud - audience
        exp - expiration time.
        iat - issued at.
        authTime - the auth time.
        apiHost - the api hostname.
        factor - the duo factor.
        Returns:
        the duo auth token.
      • createJWTJson

        private String createJWTJson​(@Nonnull
                                     String authResult,
                                     @Nonnull
                                     String authResultMessage,
                                     @Nonnull
                                     String aud,
                                     @Nonnull
                                     Instant exp,
                                     @Nonnull
                                     Instant iat,
                                     @Nonnull
                                     Instant authTime,
                                     @Nonnull
                                     String apiHost,
                                     @Nonnull
                                     String factor)
        Create a JWT token in JSON using the claims arguments.
        Parameters:
        authResult - the authentication result e.g. allow.
        authResultMessage - a user friendly result message.
        aud - audience
        exp - expiration time.
        iat - issued at.
        authTime - the auth time.
        apiHost - the api host.
        factor - the factor.
        Returns:
        the duo auth token.
      • createJWTJsonWithNoAuthResult

        private String createJWTJsonWithNoAuthResult​(@Nonnull
                                                     String authResult,
                                                     @Nonnull
                                                     String authResultMessage,
                                                     @Nonnull
                                                     String aud,
                                                     @Nonnull
                                                     Instant exp,
                                                     @Nonnull
                                                     Instant iat,
                                                     @Nonnull
                                                     Instant authTime,
                                                     @Nonnull
                                                     String apiHost,
                                                     @Nonnull
                                                     String factor)
        Create a JWT token in JSON without the auth_result element.
        Parameters:
        authResult - the authentication result e.g. allow.
        authResultMessage - a user friendly result message.
        aud - audience
        exp - expiration time.
        iat - issued at.
        authTime - the auth time.
        apiHost - the api host.
        factor - the factor.
        Returns:
        the duo auth token.
      • createJWTJsonMissingAudAndExpClaims

        private String createJWTJsonMissingAudAndExpClaims​(@Nonnull
                                                           String authResult,
                                                           @Nonnull
                                                           String authResultMessage,
                                                           @Nonnull
                                                           Instant iat,
                                                           @Nonnull
                                                           Instant authTime,
                                                           @Nonnull
                                                           String apiHost,
                                                           @Nonnull
                                                           String factor)
        Create a JWT token in JSON using the claims arguments present, but missing the 'aud' and 'exp' claims.
        Parameters:
        authResult - the authentication result e.g. allow.
        authResultMessage - a user friendly result message.
        iat - issued at.
        authTime - the auth time.
        apiHost - the api host.
        factor - the factor.
        Returns:
        the duo auth token.
      • createJWTJsonWithNbf

        private String createJWTJsonWithNbf​(@Nonnull
                                            String authResult,
                                            @Nonnull
                                            String authResultMessage,
                                            @Nonnull
                                            String aud,
                                            @Nonnull
                                            Instant exp,
                                            @Nonnull
                                            Instant iat,
                                            @Nonnull
                                            Instant authTime,
                                            @Nonnull
                                            Instant nbf,
                                            @Nonnull
                                            String apiHost,
                                            @Nonnull
                                            String factor)
        Create a JWT token in JSON using the claims arguments. Includes the not before claim which is not part of the normal Duo (or OIDC) response, but is part of the JWT spec.
        Parameters:
        authResult - the authentication result e.g. allow.
        authResultMessage - a user friendly result message.
        aud - audience
        exp - expiration time.
        iat - issued at.
        authTime - the auth time.
        nbf - the not before time.
        apiHost - the api host.
        factor - the factor.
        Returns:
        the duo auth token.
      • addAttemptedFlow

        protected void addAttemptedFlow​(@Nonnull
                                        String flowId)
        Add an AuthenticationFlowDescriptor to the AuthenticationContext with the specified flow ID.
        Parameters:
        flowId - the flow ID.
      • assertEventIdFromProfileRequestContext

        protected void assertEventIdFromProfileRequestContext​(@Nonnull
                                                              String eventId)
        Check the EventContext in the ProfileRequestContext is a String which represents the eventId argument.
        Parameters:
        eventId - the eventId to check.
      • assertEventId

        protected void assertEventId​(@Nullable
                                     Event event,
                                     @Nonnull
                                     String eventId)
        Check the event ID matches the eventId.
        Parameters:
        event - the event to check the ID of.
        eventId - the ID to match.
      • addDuoContext

        protected void addDuoContext()
        Add the Duo authentication context to the authentication context.
      • addDuoIntegrationToContext

        protected void addDuoIntegrationToContext()
        Add fabricated duo integration to the duo context.
      • createDummyDuoIntegration

        @Nonnull
        protected DefaultDuoOIDCIntegration createDummyDuoIntegration()
        Create a dummy Duo integration.
        Returns:
        a dummy Duo integration.