package com.foxx.androidcast.remoteaccess;

import org.json.JSONObject;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class WireGuardConfigBuilderTest {

    @Test
    public void buildsConfigFromCredentials() throws Exception {
        JSONObject creds = new JSONObject();
        creds.put("interface_private_key", "aPrivKey=");
        creds.put("interface_address", "10.66.66.5/32");
        creds.put("peer_public_key", "aPubKey=");
        creds.put("peer_endpoint", "example.org:51820");
        creds.put("peer_allowed_ips", "10.66.66.1/32");
        String cfg = WireGuardConfigBuilder.fromConnectCredentials(creds);
        assertTrue(cfg.contains("[Interface]"));
        assertTrue(cfg.contains("PrivateKey = aPrivKey="));
        assertTrue(cfg.contains("PublicKey = aPubKey="));
        assertTrue(cfg.contains("Endpoint = example.org:51820"));
    }

    @Test
    public void emptyWhenMissingKeys() throws Exception {
        JSONObject creds = new JSONObject();
        creds.put("interface_address", "10.66.66.5/32");
        assertTrue(WireGuardConfigBuilder.fromConnectCredentials(creds).isEmpty());
    }
}
