Search in sources :

Example 51 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class PortAlreadyInUseTest method go.

protected void go() throws Exception {
    jmxPort = Utils.getFreePort();
    occupyPort();
    log.info("Attempting to start a VM using the same port.");
    OutputAnalyzer out = this.runVM();
    out.shouldContain("Port already in use");
    log.info("Failed as expected.");
    log.info("Trying again using retries.");
    this.run();
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 52 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class DynamicLauncher method runVM.

protected OutputAnalyzer runVM() throws Exception {
    String[] options = this.options();
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(options);
    OutputAnalyzer out = new OutputAnalyzer(pb.start());
    System.out.println(out.getStdout());
    System.err.println(out.getStderr());
    return out;
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 53 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class KinitConfPlusProps method checkTicketFlags.

// check if a ticket has forwardable and proxiable flags
private static boolean checkTicketFlags() {
    String[] command = new String[] { KLIST, "-f", "-c", CC_FILENAME };
    try {
        OutputAnalyzer out = ProcessTools.executeCommand(command);
        out.shouldHaveExitValue(0);
        out.shouldContain("FORWARDABLE");
        out.shouldContain("PROXIABLE");
    } catch (Throwable e) {
        System.out.println("Unexpected exception: " + e);
        e.printStackTrace(System.out);
        return false;
    }
    return true;
}
Also used : OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Example 54 with OutputAnalyzer

use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.

the class KinitConfPlusProps method main.

public static void main(String[] args) throws Exception {
    // define principals
    Map<String, String> principals = new HashMap<>();
    principals.put(USER_PRINCIPAL, null);
    principals.put(KRBTGT_PRINCIPAL, null);
    System.setProperty("java.security.krb5.conf", KRB5_CONF_FILENAME);
    // start a local KDC instance
    KDC kdc = KDC.startKDC(HOST, null, REALM, principals, KEYTAB_FILE, KDC.KtabMode.APPEND);
    KDC.saveConfig(KRB5_CONF_FILENAME, kdc, "forwardable = true", "proxiable = true");
    boolean success = true;
    /*
         * kinit should fail since java.security.krb5.kdc
         * and java.security.krb5.realm properties override correct values
         * in krb5 conf file
         */
    String[] command = { KINIT, "-k", "-J-Djava.security.krb5.realm=" + REALM, // without port
    "-J-Djava.security.krb5.kdc=" + HOST, "-J-Djava.security.krb5.conf=" + KRB5_CONF_FILENAME, "-t", KEYTAB_FILE, "-c", CC_FILENAME, USER };
    try {
        OutputAnalyzer out = ProcessTools.executeCommand(command);
        out.shouldHaveExitValue(-1);
        out.shouldContain(PortUnreachableException.class.getName());
    } catch (Throwable e) {
        System.out.println("Unexpected exception: " + e);
        e.printStackTrace(System.out);
        success = false;
    }
    /*
         * kinit should succeed
         * since realm should be picked up from principal name
         */
    command = new String[] { KINIT, "-k", "-J-Djava.security.krb5.realm=" + ANOTHER_REALM, "-J-Djava.security.krb5.kdc=" + HOST, "-J-Djava.security.krb5.conf=" + KRB5_CONF_FILENAME, "-t", KEYTAB_FILE, "-c", CC_FILENAME, USER_PRINCIPAL };
    try {
        OutputAnalyzer out = ProcessTools.executeCommand(command);
        out.shouldHaveExitValue(0);
        out.shouldContain(CC_FILENAME);
    } catch (Throwable e) {
        System.out.println("Unexpected exception: " + e);
        e.printStackTrace(System.out);
        success = false;
    }
    success &= checkTicketFlags();
    /*
         * kinit should succeed
         * since realm should be picked up from principal name,
         * and other data should come from krb5 conf file
         */
    command = new String[] { KINIT, "-k", "-J-Djava.security.krb5.conf=" + KRB5_CONF_FILENAME, "-t", KEYTAB_FILE, "-c", CC_FILENAME, USER_PRINCIPAL };
    try {
        OutputAnalyzer out = ProcessTools.executeCommand(command);
        out.shouldHaveExitValue(0);
        out.shouldContain(CC_FILENAME);
    } catch (Throwable e) {
        System.out.println("Unexpected exception: " + e);
        e.printStackTrace(System.out);
        success = false;
    }
    success &= checkTicketFlags();
    // kinit should succeed even if a principal name doesn't have realm
    command = new String[] { KINIT, "-k", "-J-Djava.security.krb5.conf=" + KRB5_CONF_FILENAME, "-t", KEYTAB_FILE, "-c", CC_FILENAME, USER };
    try {
        OutputAnalyzer out = ProcessTools.executeCommand(command);
        out.shouldHaveExitValue(0);
        out.shouldContain(CC_FILENAME);
    } catch (Throwable e) {
        System.out.println("Unexpected exception: " + e);
        e.printStackTrace(System.out);
        success = false;
    }
    success &= checkTicketFlags();
    if (!success) {
        throw new RuntimeException("At least one test case failed");
    }
    System.out.println("Test passed");
}
Also used : PortUnreachableException(java.net.PortUnreachableException) HashMap(java.util.HashMap) OutputAnalyzer(jdk.testlibrary.OutputAnalyzer)

Aggregations

OutputAnalyzer (jdk.testlibrary.OutputAnalyzer)54 File (java.io.File)5 JDKToolLauncher (jdk.testlibrary.JDKToolLauncher)5 ArrayList (java.util.ArrayList)4 PortUnreachableException (java.net.PortUnreachableException)1 LocateRegistry (java.rmi.registry.LocateRegistry)1 Registry (java.rmi.registry.Registry)1 KeyStore (java.security.KeyStore)1 X509Certificate (java.security.cert.X509Certificate)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MissingResourceException (java.util.MissingResourceException)1 ProcessThread (jdk.testlibrary.ProcessThread)1