package com.foxx.androidcast.remoteaccess;

import org.junit.Test;

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

public class RemoteAccessVpnRoutingTest {

    @Test
    public void resolveAllowedIps_hubOnlyUsesBeValue() {
        assertEquals("172.200.2.1/32", RemoteAccessVpnRouting.resolveAllowedIps(
                RemoteAccessVpnRouting.RouteScope.HUB_ONLY, "172.200.2.1/32"));
    }

    @Test
    public void resolveAllowedIps_hubOnlyDefaultWhenEmpty() {
        assertEquals(RemoteAccessVpnRouting.DEFAULT_HUB_ALLOWED_IPS, RemoteAccessVpnRouting.resolveAllowedIps(
                RemoteAccessVpnRouting.RouteScope.HUB_ONLY, ""));
    }

    @Test
    public void resolveAllowedIps_fullTunnel() {
        assertEquals(RemoteAccessVpnRouting.FULL_TUNNEL_ALLOWED_IPS, RemoteAccessVpnRouting.resolveAllowedIps(
                RemoteAccessVpnRouting.RouteScope.FULL_TUNNEL, "172.200.2.1/32"));
    }

    @Test
    public void appendInterfaceExtras_appOnly() {
        StringBuilder sb = new StringBuilder();
        RemoteAccessVpnRouting.appendInterfaceExtras(
                sb,
                RemoteAccessVpnRouting.AppScope.THIS_APP_ONLY,
                "com.foxx.androidcast");
        assertTrue(sb.toString().contains("IncludedApplications = com.foxx.androidcast"));
    }

    @Test
    public void fromStored_invalidDefaults() {
        assertEquals(RemoteAccessVpnRouting.RouteScope.HUB_ONLY,
                RemoteAccessVpnRouting.RouteScope.fromStored("bogus"));
        assertEquals(RemoteAccessVpnRouting.AppScope.ALL_APPS,
                RemoteAccessVpnRouting.AppScope.fromStored(""));
    }
}
