src/test/java/edu/ucla/library/iiif/auth/services/AccessCookieServiceTest.java
@Test
    public final void testValidateGeneratedCookie(final Vertx aVertx, final VertxTestContext aContext) {
        final String clientIpAddress = LOCALHOST;
        final boolean isCampusNetwork = true;
        final boolean isDegradedAllowed = false;

        myServiceProxy.generateCookie(clientIpAddress, isCampusNetwork, isDegradedAllowed).compose(cookie -> {
            // The result is base64-encoded JSON with three keys
            final JsonObject decodedCookie = new JsonObject(new String(Base64.getDecoder().decode(cookie.getBytes())));

            for (final String key : List.of(CookieJsonKeys.VERSION, CookieJsonKeys.SECRET, CookieJsonKeys.NONCE)) {
                assertTrue(decodedCookie.containsKey(key));
            }

            return myServiceProxy.decryptCookie(cookie, clientIpAddress);
        }).onSuccess(decryptedCookie -> {
            final JsonObject expected = new JsonObject().put(CookieJsonKeys.CLIENT_IP_ADDRESS, clientIpAddress)
                    .put(CookieJsonKeys.CAMPUS_NETWORK, isCampusNetwork)
                    .put(CookieJsonKeys.DEGRADED_ALLOWED, isDegradedAllowed);

            completeIfExpectedElseFail(decryptedCookie, expected, aContext);
        }).onFailure(aContext::failNow);
    }
/**
     * Tests cookie generation and decryption.
     *
     * @param aVertx A Vert.x instance
     * @param aContext A test context
     */
Tests cookie generation and decryption.
@param aVertx A Vert.x instance
@param aContext A test context
Tests cookie generation and decryption . @param aVertx A Vert . x instance @param aContext A test context
@Test
    public final void testValidateGeneratedCookie(final Vertx aVertx, final VertxTestContext aContext) {
        final String clientIpAddress = LOCALHOST;
        final boolean isCampusNetwork = true;
        final boolean isDegradedAllowed = false;
        myServiceProxy.generateCookie(clientIpAddress, isCampusNetwork, isDegradedAllowed).compose(cookie -> {
            final JsonObject decodedCookie = new JsonObject(new String(Base64.getDecoder().decode(cookie.getBytes())));
            for (final String key : List.of(CookieJsonKeys.VERSION, CookieJsonKeys.SECRET, CookieJsonKeys.NONCE)) {
                assertTrue(decodedCookie.containsKey(key));
            }
            return myServiceProxy.decryptCookie(cookie, clientIpAddress);
        }).onSuccess(decryptedCookie -> {
            final JsonObject expected = new JsonObject().put(CookieJsonKeys.CLIENT_IP_ADDRESS, clientIpAddress)
                    .put(CookieJsonKeys.CAMPUS_NETWORK, isCampusNetwork)
                    .put(CookieJsonKeys.DEGRADED_ALLOWED, isDegradedAllowed);
            completeIfExpectedElseFail(decryptedCookie, expected, aContext);
        }).onFailure(aContext::failNow);
    }
@ Test public final void testValidateGeneratedCookie ( final Vertx aVertx , final VertxTestContext aContext ) { final String clientIpAddress = LOCALHOST ; final boolean isCampusNetwork = true ; final boolean isDegradedAllowed = false ; myServiceProxy . generateCookie ( clientIpAddress , isCampusNetwork , isDegradedAllowed ) . compose ( cookie -> { final JsonObject decodedCookie = new JsonObject ( new String ( Base64 . getDecoder ( ) . decode ( cookie . getBytes ( ) ) ) ) ; for ( final String key : List . of ( CookieJsonKeys . VERSION , CookieJsonKeys . SECRET , CookieJsonKeys . NONCE ) ) { assertTrue ( decodedCookie . containsKey ( key ) ) ; } return myServiceProxy . decryptCookie ( cookie , clientIpAddress ) ; } ) . onSuccess ( decryptedCookie -> { final JsonObject expected = new JsonObject ( ) . put ( CookieJsonKeys . CLIENT_IP_ADDRESS , clientIpAddress ) . put ( CookieJsonKeys . CAMPUS_NETWORK , isCampusNetwork ) . put ( CookieJsonKeys . DEGRADED_ALLOWED , isDegradedAllowed ) ; completeIfExpectedElseFail ( decryptedCookie , expected , aContext ) ; } ) . onFailure ( aContext :: failNow ) ; }
Tests cookie generation and decryption.
Tests cookie generation and decryption .
// The result is base64-encoded JSON with three keys