package com.foxx.androidcast.remoteaccess.control;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;

public class RemoteAccessControlHttpServerTest {

    @Test
    public void parseRequest_readsPostBody() throws Exception {
        String raw = "POST /api/settings HTTP/1.1\r\n"
                + "Host: localhost\r\n"
                + "Content-Length: 11\r\n"
                + "\r\n"
                + "{\"ok\":true}";
        ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]);
        RemoteAccessControlHttpServer.HttpRequest req =
                RemoteAccessControlHttpServer.parseRequest(raw, in);
        assertNotNull(req);
        assertEquals("POST", req.method);
        assertEquals("/api/settings", req.path);
        assertEquals("{\"ok\":true}", req.body);
    }

    @Test
    public void shellAcceptKey_matchesRfc6455Fixture() {
        String key = "dGhlIHNhbXBsZSBub25jZQ==";
        String accept = RemoteAccessControlShellHandler.computeAcceptKey(key);
        assertEquals("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", accept);
    }
}
