package umm3601.digitalDisplayGarden.Authentication;


import org.junit.Before;
import org.junit.Test;

import java.security.NoSuchAlgorithmException;

import static java.lang.Thread.sleep;
import static org.junit.Assert.*;

public class TestAuthorizedCookieBody {

    Auth auth;

    @Before
    public void setup() throws NoSuchAlgorithmException{
        auth = new Auth("fakeID", "fakeSecret", "callback");
    }

    @Test
    public void testThatCookieBodyIsAuthorizable(){
        String cookieBody = auth.generateCookieBody(120);
        assertNotNull(cookieBody);
        assertNotEquals("",cookieBody);

        boolean authorized = auth.authorized(cookieBody);
        assertTrue(authorized);
    }

    @Test
    public void testThatCookieBodyIsExpired(){
        String cookieBody = auth.generateCookieBody(0);
        boolean authorized = auth.authorized(cookieBody);
        assertFalse(authorized);
    }

    @Test
    public void testThatInvalidCookieBodyIsNotAuthorized(){
        boolean authorized = auth.authorized("SWvvnS4x1qPOQRUHbuX6s//TrXTk/ir74LDBp");
        assertFalse(authorized);
    }

}

@@ -1113,10 +1113,554 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testGenerateAndUnpackSecretSuccess()%7B%0A        String secret = auth.generateSharedGoogleSecret(%22someURL%22);%0A        RedirectToken redToken = auth.unpackSharedGoogleSecret(secret);%0A        assertEquals(%22someURL%22, redToken.originatingURL);%0A    %7D%0A%0A    @Test%0A    public void testGenerateAndUnpackSecretFailure()%7B%0A        String secret = auth.generateSharedGoogleSecret(%22someURL%22);%0A        secret = secret + %22fasd%22;%0A        RedirectToken redToken = auth.unpackSharedGoogleSecret(secret);%0A        assertNull(redToken);%0A%0A    %7D%0A
 %7D%0A

Test generating a secret that can be unpacked with the correct URL.