view tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/UnsignedAppletTrustConfirmationTest.java @ 1044:b668c06dcb36

Saving of status of dialogs for "whole codebase" now includes also document base
author Jiri Vanek <jvanek@redhat.com>
date Tue, 08 Sep 2015 15:24:32 +0200
parents f544f5b40bb7
children b3779eedeef1
line wrap: on
line source

package net.sourceforge.jnlp.security.appletextendedsecurity;

import static org.junit.Assert.assertEquals;

import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;

public class UnsignedAppletTrustConfirmationTest {

    @Test
    public void testToRelativePaths() throws Exception {
        /* Absolute -> Relative */
        assertEquals(Arrays.asList("test.jar"),
                UnsignedAppletTrustConfirmation.toRelativePaths(Arrays.asList("http://example.com/test.jar"), "http://example.com/"));

        /* Relative is unchanged */
        assertEquals(Arrays.asList("test.jar"),
                UnsignedAppletTrustConfirmation.toRelativePaths(Arrays.asList("test.jar"), "http://example.com/"));

        /* Different root URL is unchanged */
        assertEquals(Arrays.asList("http://example2.com/test.jar"),
                UnsignedAppletTrustConfirmation.toRelativePaths(Arrays.asList("http://example2.com/test.jar"), "http://example.com/"));

        /* Path with invalid URL characters is handled */
        assertEquals(Arrays.asList("test .jar"),
                UnsignedAppletTrustConfirmation.toRelativePaths(Arrays.asList("http://example.com/test .jar"), "http://example.com/"));
    }
    
    
    @Test
    public void testSripFile() throws Exception {
        String sample = "http://aa.bb/";
        String result = UnsignedAppletTrustConfirmation.stripFile(new URL(sample));
        assertEquals(sample, result);
        sample = "http://aa.bb";
        result = UnsignedAppletTrustConfirmation.stripFile(new URL(sample));
        assertEquals(sample + "/", result);
        sample = "http://aa.bb/";
        result = UnsignedAppletTrustConfirmation.stripFile(new URL(sample + "cc"));
        assertEquals(sample, result);
        sample = "http://aa.bb/cc/";
        result = UnsignedAppletTrustConfirmation.stripFile(new URL(sample));
        assertEquals(sample, result);
        sample = "http://aa.bb/some/complicated/";
        result = UnsignedAppletTrustConfirmation.stripFile(new URL(sample + "some"));
        assertEquals(sample, result);
        sample = "http://aa.bb/some/complicated/some/";
        result = UnsignedAppletTrustConfirmation.stripFile(new URL(sample));
        assertEquals(sample, result);
        sample = "http://aa.bb/some/";
        result = UnsignedAppletTrustConfirmation.stripFile(new URL(sample + "strange?a=b"));
        assertEquals(sample, result);
        sample = "http://aa.bb/some/strange/";
        result = UnsignedAppletTrustConfirmation.stripFile(new URL(sample + "?a=b"));
        assertEquals(sample, result);
        
    }
}