Package tests

Source Code of tests.AuthTest

package tests;

import java.io.IOException;

import junit.framework.TestCase;

import org.stringtree.mojasef.HTTPConstants;
import org.stringtree.mojasef.local.LocalRequest;
import org.stringtree.mojasef.local.LocalServer;
import org.stringtree.tract.ByteTract;

public class AuthTest extends TestCase {
    LocalServer server;
    ByteTract request;
    ByteTract response;
   
    public void setUp() throws IOException {
        server = new LocalServer("src/test/files/auth/http.spec");
    }

    public void testUnknown() {
        request = new LocalRequest("private/12346");
        response = server.request(request);
        assertEquals("404", response.get(HTTPConstants.RESPONSE_CODE));
    }

    public void testKnownButUnauthorized() {
        request = new LocalRequest("private/12345");
        response = server.request(request);
        assertEquals("401", response.get(HTTPConstants.RESPONSE_CODE));
        assertEquals("Basic realm=\"private:12345\"", response.get("WWW-Authenticate"));
    }

    public void testIncorrectlyAuthorized() {
        request = new LocalRequest("private/12345");
        request.put("Authorization", "Basic 12345:2222");
        response = server.request(request);
        assertEquals("401", response.get(HTTPConstants.RESPONSE_CODE));
        assertEquals("Basic realm=\"private:12345\"", response.get("WWW-Authenticate"));
    }

    public void testCorrectlyAuthorized() {
        request = new LocalRequest("private/12345");
        request.put("Authorization", "Basic 12345:1111");
        response = server.request(request);
        assertEquals("200", response.get(HTTPConstants.RESPONSE_CODE));
        assertEquals("hello", response.getContent());
    }
}
TOP

Related Classes of tests.AuthTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.