Search in sources :

Example 6 with Method

use of com.google.cloud.conformance.storage.v1.Method in project java-storage by googleapis.

the class V4PostPolicyTest method testCases.

/**
 * Loads all of the tests and return a {@code Collection<Object[]>} representing the set of tests.
 * Each entry in the returned collection is the set of parameters to the constructor of this test
 * class.
 *
 * <p>The results of this method will then be run by JUnit's Parameterized test runner
 */
@Parameters(name = "{2}")
public static Collection<Object[]> testCases() throws IOException {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    InputStream credentialsStream = cl.getResourceAsStream(SERVICE_ACCOUNT_JSON_RESOURCE);
    assertNotNull(String.format("Unable to load service account json: %s", SERVICE_ACCOUNT_JSON_RESOURCE), credentialsStream);
    InputStream dataJson = cl.getResourceAsStream(TEST_DATA_JSON_RESOURCE);
    assertNotNull(String.format("Unable to load test definition: %s", TEST_DATA_JSON_RESOURCE), dataJson);
    ServiceAccountCredentials serviceAccountCredentials = ServiceAccountCredentials.fromStream(credentialsStream);
    InputStreamReader reader = new InputStreamReader(dataJson, Charsets.UTF_8);
    TestFile.Builder testBuilder = TestFile.newBuilder();
    JsonFormat.parser().merge(reader, testBuilder);
    TestFile testFile = testBuilder.build();
    List<PostPolicyV4Test> tests = testFile.getPostPolicyV4TestsList();
    ArrayList<Object[]> data = new ArrayList<>(tests.size());
    for (PostPolicyV4Test test : tests) {
        data.add(new Object[] { test, serviceAccountCredentials, test.getDescription() });
    }
    return data;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) TestFile(com.google.cloud.conformance.storage.v1.TestFile) ArrayList(java.util.ArrayList) ServiceAccountCredentials(com.google.auth.oauth2.ServiceAccountCredentials) PostPolicyV4Test(com.google.cloud.conformance.storage.v1.PostPolicyV4Test) Parameters(org.junit.runners.Parameterized.Parameters)

Example 7 with Method

use of com.google.cloud.conformance.storage.v1.Method in project jargyle by jh3nd3rs0n.

the class Socks5HostResolver method resolve.

@Override
public InetAddress resolve(final String host) throws IOException {
    if (host == null) {
        return InetAddress.getLoopbackAddress();
    }
    Properties properties = this.socks5Client.getProperties();
    AddressType addressType = AddressType.valueForString(host);
    if (!addressType.equals(AddressType.DOMAINNAME) || !properties.getValue(Socks5PropertySpecConstants.SOCKS5_RESOLVE_USE_RESOLVE_COMMAND).booleanValue()) {
        return InetAddress.getByName(host);
    }
    Socket socket = this.socks5Client.newInternalSocket();
    this.socks5Client.configureInternalSocket(socket);
    Socket sock = this.socks5Client.getConnectedInternalSocket(socket, true);
    Method method = this.socks5Client.negotiateMethod(sock);
    MethodEncapsulation methodEncapsulation = this.socks5Client.doMethodSubnegotiation(method, sock);
    Socket sck = methodEncapsulation.getSocket();
    Socks5Request socks5Req = Socks5Request.newInstance(Command.RESOLVE, host, 0);
    this.socks5Client.sendSocks5Request(socks5Req, sck);
    Socks5Reply socks5Rep = null;
    try {
        socks5Rep = this.socks5Client.receiveSocks5Reply(sck);
    } catch (FailureSocks5ReplyException e) {
        Reply reply = e.getFailureSocks5Reply().getReply();
        if (reply.equals(Reply.HOST_UNREACHABLE)) {
            throw new UnknownHostException(host);
        } else {
            throw e;
        }
    }
    InetAddress inetAddress = InetAddress.getByName(socks5Rep.getServerBoundAddress());
    return InetAddress.getByAddress(host, inetAddress.getAddress());
}
Also used : MethodEncapsulation(com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation) Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) UnknownHostException(java.net.UnknownHostException) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) Properties(com.github.jh3nd3rs0n.jargyle.client.Properties) AddressType(com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType) InetAddress(java.net.InetAddress) Socket(java.net.Socket)

Aggregations

Method (com.github.jh3nd3rs0n.jargyle.transport.socks5.Method)4 InputStream (java.io.InputStream)4 IOException (java.io.IOException)3 ClientMethodSelectionMessage (com.github.jh3nd3rs0n.jargyle.transport.socks5.ClientMethodSelectionMessage)2 Methods (com.github.jh3nd3rs0n.jargyle.transport.socks5.Methods)2 ServerMethodSelectionMessage (com.github.jh3nd3rs0n.jargyle.transport.socks5.ServerMethodSelectionMessage)2 Socks5Request (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request)2 ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)2 TestFile (com.google.cloud.conformance.storage.v1.TestFile)2 InputStreamReader (java.io.InputStreamReader)2 Socket (java.net.Socket)2 Properties (com.github.jh3nd3rs0n.jargyle.client.Properties)1 Route (com.github.jh3nd3rs0n.jargyle.server.Route)1 WorkerContext (com.github.jh3nd3rs0n.jargyle.server.WorkerContext)1 Socks5RequestRoutingRule (com.github.jh3nd3rs0n.jargyle.server.rules.impl.Socks5RequestRoutingRule)1 AddressType (com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType)1 MethodEncapsulation (com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation)1 Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply)1 Socks5Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)1 JsonParser (com.google.api.client.json.JsonParser)1