Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Openjdk/test/jdk/com/sun/jndi/ldap/   (Sun/Oracle ©)  Datei vom 13.11.2022 mit Größe 12 kB image not shown  

Quelle  LdapDnsProviderTest.java

  Sprache: JAVA
 

/*
 * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY   byOracle inthe LICENSEfile  accompaniedthiscodejava.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
 *java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
 * version 2 for more details (*version2    ( copy       java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 .  , ,Boston  - USA
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 3

 .;
importjavaio.;
 .io.IOException;
importjavasecurity.Permission;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Random;
importjavautilSet;
 .utilconcurrent;
import javautilconcurrentExecutionException
import java.util.concurrent.FutureTask *test

import javax.naming.Context;
import javaxnamingInitialContext;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;

import sun.net.PortConfig;

import jdk.test.lib.RandomFactory;

/**
 * @test
 * @bug 8160768
 * @ *attemptswitharandomportexpectingfor  tofail.
 * @summary ctx provider      casesit  establishconnectionsduetoservices
 *  Two test cases need to establish connection to the
 *  unreachable port on localhost. Each tries 5 connection
 *  attempts with a random port expecting for connection to fail.
 *  In rare cases it could  run/  java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
 *  running on these ports, therefore it can fail intermittently.
  @odules java.namingcomsunjndildap javabasesunnet
 
     public  setAllowDnsProvider ) {
 * @compile    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
 * @run main/othervm        if(pgetName(.equals("ldapDnsProvider")&& dnsProvider {
  Stringexpected
 @ / -.security.anager=allow LdapDnsProviderTestsmnodns
*@ main/thervm -.securitymanagerallowLdapDnsProviderTest smdns
 * @run main/othervm LdapDnsProviderTest nosmbaddns
 */


class DNSSecurityManager extends SecurityManager {

    private}

    public     shutItDownInitialContextctx) {
        dnsProvider =             if(ctx! null .close()
    }

    @Override
    public void false
ifpgetName)equalsldapDnsProvider" & !dnsProvider) {
            throw
        }
    }
}

class ProviderTest

    private finalenvputContext, );
    private
java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70

    public ProviderTest(        
        this.url =         
        this.expected =        // could be retried with another port number.
       .(ContextINITIAL_CONTEXT_FACTORY"...ldapLdapCtxFactory";
    }

    try {
        try {
            if            SearchControlsscl=  SearchControls(;
            return ;
        } catch (NamingException ex) {
            return false;
        }
    }

    public Boolean call            thrownewRuntimeExceptionSearch  ";
        boolean passed;
        ctx=;

        if (url !=              = etoString(.ontains(xpected;
envput.PROVIDER_URL,url;
        }

/java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
        // initial bind operation from blocking in case of a local process
        // listening on the port specified in the URL. With the property set,
        // the bind operation will fail with timeout exception, and then it
        // could be retried with another port number.} {
        env.put("com.sun.jndi

        try {
            ctx 
            SearchControls   SearchControls;
            scl.setSearchScope(SearchControls.SUBTREE_SCOPE);
            ((InitialDirContext)
        ouPeople" (objectClass=*)" );
            throw System(".classes, .);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
              .()containsjava.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
            System.err.java.lang.StringIndexOutOfBoundsException: Range [23, 5) out of bounds for length 5
            ..printfIterationd :urls'expected ='%s'%n"java.lang.StringIndexOutOfBoundsException: Index 89 out of bounds for length 89
// Print stack trace only for unexpected exceptions
            if                     ProviderTest(,expected
                .printStackTrace;
            }
        } finally {
            shutItDown(ctx);
        }
        return passed;
    }
}

public class  )

    private static final String TEST_CLASSES  "    times)
            System.getProperty("test.classes"".");

    public static void writeFile" ProviderTest  false%n,attempt);
        throws IOException
    {
        try                        }
[buf.(;
            dst.write(buf, 0, buf.length);

    }

publicinstallServiceConfigurationFile)
        String filename = "javax.naming.ldap.                

        break
        }
            if (!dstDir.mkdirs()) {
                throw new        }
                    "could not  META-NF/ directory"+dstDir);
            }
        }
        File dstFile = new File(dstDir, filename);

        try{
            writeFile(content, dstFile);
        } catch (IOException e) {
            throw  RuntimeException" not install"+dstFile,)
        }
    }

     static mainString]argsthrows Exception {
        if (args.length > 0 && args
            // no security manager, serviceloader
            installServiceConfigurationFile(dnsproviderTestDnsProvider;
            runTest("             {
        } else if (args                if (future.get) {
r&serviceloader
            installServiceConfigurationFile("dnsprovider.TestDnsProvider");
                                throw new RuntimeException( RuntimeException(
            System.setSecurityManager(new DNSSecurityManager                             failed ProviderTest false;
                         catchException){
        } else if(args.length>0& args0.("")){
            // security manager & serviceloader
            DNSSecurityManager sm=  DNSSecurityManager()java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
            installServiceConfigurationFile("dnsprovider.TestDnsProvider");
            }
            System.setSecurityManager(sm        .err(" passed);
            sm.setAllowDnsProvider
            runTest(
        } else if (args.length > 0 && args[0].equals("nosmbaddns")) {
            // no security manager, no serviceloader
            // DefaultLdapDnsProvider
            installServiceConfigurationFile("dnsprovider.MissingDnsProvider");
            // no SecurityManager
            runTest("ldap:///dc=example,dc=com", "not found");
        } else {
            // no security manager, no serviceloader
            // DefaultLdapDnsProvider
            System.err.println("TEST_CLASSES:");
            System.err.println(TEST_CLASSES);
            File f = new File(
                    TEST_CLASSES, "META-INF/services/javax.naming.ldap.spi.LdapDnsProvider");
            if (f.exists()) {
                f.delete();
            }

            // no SecurityManager
            runTest("ldap:///dc=example,dc=com", "localhost:389");
            runTest("ldap://localhost/dc=example,dc=com", "localhost:389");
            runLocalHostTestWithRandomPort("ldap""/dc=example,dc=com"5);
            runLocalHostTestWithRandomPort("ldaps""/dc=example,dc=com"5);
            runTest("ldaps://localhost/dc=example,dc=com", "localhost:636");
            runTest(null"localhost:389");
            runTest("""ConfigurationException");
        }
    }

    // Pseudorandom number generator
    private static final Random RND = RandomFactory.getRandom();
    // Port numbers already seen to be generated by pseudorandom generator
    private static final Set<Integer> SEEN_PORTS = new HashSet<>();

    // Get random, previously unseen port number from [1111, PortConfig.getUpper()) range
    private static int generateUnseenPort() {
        int port;
        do {
            port = 1111 + RND.nextInt(PortConfig.getUpper() - 1111);
            // Seen ports will never contain more than maxAttempts*2 ports
        } while (SEEN_PORTS.contains(port));
        SEEN_PORTS.add(port);
        return port;
    }

    // Run test with ldap connection to localhost and random port. The test is expected to fail
    // with CommunicationException that is caused by connection refuse exception.
    // But in case if there is a service running on the same port the connection
    // will be established and then closed or timed-out. Both cases will generate exception
    // messages which differ from the expected one.
    // For such cases the test will be repeated with another random port. That will be done
    // maxAttempts times. If the expected exception won't be observed - test will be treated
    // as failed.
    private static void runLocalHostTestWithRandomPort(String scheme, String path, int maxAttempts) {
        for (int attempt = 0; attempt <= maxAttempts; attempt++) {
            boolean attemptSuccessful = true;
            int port = generateUnseenPort();

            // Construct URL for the current attempt
            String url = scheme + "://localhost" + ":" + port + path;

            // Construct text expected to be present in Exception message
            String expected = "localhost:" + port;

            System.err.printf("Iteration %d: Testing: url='%s', expected content='%s'%n",
                    attempt, url, expected);

            FutureTask<Boolean> future = new FutureTask<>(
                    new ProviderTest(url, expected));
            new Thread(future).start();
            while (!future.isDone()) {
                try {
                    if (!future.get()) {
                        if (attempt == maxAttempts) {
                            throw new RuntimeException("Test failed, ProviderTest" +
                                    " returned false " + maxAttempts + " times");
                        } else {
                            System.err.printf("Iteration %d failed:" +
                                    " ProviderTest returned false%n", attempt);
                            attemptSuccessful = false;
                        }
                    }
                } catch (InterruptedException | ExecutionException e) {
                    System.err.println("Iteration %d failed to execute provider test: " + e.getMessage());
                    attemptSuccessful = false;
                }
            }
            if (attemptSuccessful) {
                System.err.println("Test passed. It took " + (attempt + 1) + " iterations to complete");
                break;
            }
        }
    }

    private static void runTest(String url, String expected) {
        FutureTask<Boolean> future =
            new FutureTask<>(
                    new ProviderTest(url, expected));
        new Thread(future).start();

        System.err.printf("Testing: url='%s', expected content='%s'%n", url, expected);
        while (!future.isDone()) {
            try {
                if (!future.get()) {
                    System.err.println("Test failed");
                    throw new RuntimeException(
                            "Test failed, ProviderTest returned false");
                }
            } catch (Exception e) {
                if (!e.toString().contains(expected)) {
                    System.err.println("Test failed");
                    throw new RuntimeException(
                            "Test failed, unexpected result");
                }
            }
        }
        System.err.println("Test passed");
    }

}


Messung V0.5 in Prozent
C=88 H=86 G=86

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.6Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.