Search in sources :

Example 1 with Method

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

the class V4SigningTest method testCases.

/**
 * Load 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<SigningV4Test> tests = testFile.getSigningV4TestsList();
    ArrayList<Object[]> data = new ArrayList<>(tests.size());
    for (SigningV4Test test : tests) {
        data.add(new Object[] { test, serviceAccountCredentials, test.getDescription() });
    }
    return data;
}
Also used : SigningV4Test(com.google.cloud.conformance.storage.v1.SigningV4Test) 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) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with Method

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

the class Socks5Client method negotiateMethod.

protected Method negotiateMethod(final Socket connectedInternalSocket) throws IOException {
    Methods methods = this.getProperties().getValue(Socks5PropertySpecConstants.SOCKS5_METHODS);
    ClientMethodSelectionMessage cmsm = ClientMethodSelectionMessage.newInstance(methods);
    Method method = null;
    try {
        InputStream inputStream = connectedInternalSocket.getInputStream();
        OutputStream outputStream = connectedInternalSocket.getOutputStream();
        outputStream.write(cmsm.toByteArray());
        outputStream.flush();
        ServerMethodSelectionMessage smsm = ServerMethodSelectionMessage.newInstanceFrom(inputStream);
        method = smsm.getMethod();
    } catch (IOException e) {
        SocksClientExceptionThrowingHelper.throwAsSocksClientException(e, this);
    }
    return method;
}
Also used : ServerMethodSelectionMessage(com.github.jh3nd3rs0n.jargyle.transport.socks5.ServerMethodSelectionMessage) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ClientMethodSelectionMessage(com.github.jh3nd3rs0n.jargyle.transport.socks5.ClientMethodSelectionMessage) Methods(com.github.jh3nd3rs0n.jargyle.transport.socks5.Methods)

Example 3 with Method

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

the class Socks5Worker method run.

public void run() throws IOException {
    this.clientFacingInputStream = this.clientFacingSocket.getInputStream();
    Method method = this.negotiateMethod();
    if (method == null) {
        return;
    }
    MethodSubnegotiationResults methodSubnegotiationResults = this.doMethodSubnegotiation(method);
    if (methodSubnegotiationResults == null) {
        return;
    }
    Socket socket = methodSubnegotiationResults.getSocket();
    this.clientFacingInputStream = socket.getInputStream();
    this.clientFacingSocket = socket;
    this.socks5WorkerContext = new Socks5WorkerContext(new WorkerContext(this.clientFacingSocket, this.socks5WorkerContext.getConfiguration(), this.socks5WorkerContext.getRoute(), this.socks5WorkerContext.getRoutes(), this.socks5WorkerContext.getClientFacingDtlsDatagramSocketFactory()));
    Socks5Request socks5Request = this.newSocks5Request();
    if (socks5Request == null) {
        return;
    }
    if (!this.canAllowSocks5Request(new Socks5RequestFirewallRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), methodSubnegotiationResults, socks5Request))) {
        return;
    }
    Route route = this.selectRoute(new Socks5RequestRoutingRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), methodSubnegotiationResults, socks5Request, this.socks5WorkerContext.getRoutes()));
    if (route == null) {
        return;
    }
    this.socks5WorkerContext = new Socks5WorkerContext(new WorkerContext(this.socks5WorkerContext.getClientFacingSocket(), this.socks5WorkerContext.getConfiguration(), route, this.socks5WorkerContext.getRoutes(), this.socks5WorkerContext.getClientFacingDtlsDatagramSocketFactory()));
    Socks5RequestWorkerContext socks5RequestWorkerContext = new Socks5RequestWorkerContext(this.socks5WorkerContext, methodSubnegotiationResults, socks5Request);
    Socks5RequestWorker socks5RequestWorker = this.newSocks5RequestWorker(socks5RequestWorkerContext);
    socks5RequestWorker.run();
}
Also used : WorkerContext(com.github.jh3nd3rs0n.jargyle.server.WorkerContext) Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) WorkerContext(com.github.jh3nd3rs0n.jargyle.server.WorkerContext) Socks5RequestRoutingRule(com.github.jh3nd3rs0n.jargyle.server.rules.impl.Socks5RequestRoutingRule) Socket(java.net.Socket) Route(com.github.jh3nd3rs0n.jargyle.server.Route)

Example 4 with Method

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

the class Socks5Worker method negotiateMethod.

private Method negotiateMethod() {
    InputStream in = new SequenceInputStream(new ByteArrayInputStream(new byte[] { Version.V5.byteValue() }), this.clientFacingInputStream);
    ClientMethodSelectionMessage cmsm = null;
    try {
        cmsm = ClientMethodSelectionMessage.newInstanceFrom(in);
    } catch (IOException e) {
        ClientFacingIOExceptionLoggingHelper.log(LOGGER, ObjectLogMessageHelper.objectLogMessage(this, "Error in parsing the method selection message " + "from the client"), e);
        return null;
    }
    LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Received %s", cmsm.toString()));
    Method method = null;
    Methods methods = this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_METHODS);
    for (Method meth : methods.toList()) {
        if (cmsm.getMethods().contains(meth)) {
            method = meth;
            break;
        }
    }
    if (method == null) {
        method = Method.NO_ACCEPTABLE_METHODS;
    }
    ServerMethodSelectionMessage smsm = ServerMethodSelectionMessage.newInstance(method);
    LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Sending %s", smsm.toString()));
    try {
        this.socks5WorkerContext.writeThenFlush(smsm.toByteArray());
    } catch (IOException e) {
        ClientFacingIOExceptionLoggingHelper.log(LOGGER, ObjectLogMessageHelper.objectLogMessage(this, "Error in writing the method selection message to " + "the client"), e);
        return null;
    }
    return smsm.getMethod();
}
Also used : ServerMethodSelectionMessage(com.github.jh3nd3rs0n.jargyle.transport.socks5.ServerMethodSelectionMessage) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) ClientMethodSelectionMessage(com.github.jh3nd3rs0n.jargyle.transport.socks5.ClientMethodSelectionMessage) Methods(com.github.jh3nd3rs0n.jargyle.transport.socks5.Methods)

Example 5 with Method

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

the class ITBlobWriteChannelTest method doJsonUnexpectedEOFTest.

private void doJsonUnexpectedEOFTest(int contentSize, int cappedByteCount) throws IOException {
    String blobPath = String.format("%s/%s/blob", testName.getMethodName(), NOW_STRING);
    BucketInfo bucketInfo = BucketInfo.of(dataGeneration.getBucketName());
    BlobInfo blobInfoGen0 = BlobInfo.newBuilder(bucketInfo, blobPath, 0L).build();
    RetryTestResource retryTestResource = RetryTestResource.newRetryTestResource(Method.newBuilder().setName("storage.objects.insert").build(), InstructionList.newBuilder().addInstructions(String.format("return-broken-stream-final-chunk-after-%dB", cappedByteCount)).build());
    RetryTestResource retryTest = testBench.createRetryTest(retryTestResource);
    StorageOptions baseOptions = StorageOptions.newBuilder().setCredentials(NoCredentials.getInstance()).setHost(testBench.getBaseUri()).setProjectId("project-id").build();
    StorageRpc noHeader = (StorageRpc) baseOptions.getRpc();
    StorageRpc yesHeader = (StorageRpc) baseOptions.toBuilder().setHeaderProvider(FixedHeaderProvider.create(ImmutableMap.of("x-retry-test-id", retryTest.id))).build().getRpc();
    // noinspection UnstableApiUsage
    StorageOptions storageOptions = baseOptions.toBuilder().setServiceRpcFactory(options -> Reflection.newProxy(StorageRpc.class, (proxy, method, args) -> {
        try {
            if ("writeWithResponse".equals(method.getName())) {
                boolean lastChunk = (boolean) args[5];
                LOGGER.info(String.format("writeWithResponse called. (lastChunk = %b)", lastChunk));
                if (lastChunk) {
                    return method.invoke(yesHeader, args);
                }
            }
            return method.invoke(noHeader, args);
        } catch (Exception e) {
            if (e.getCause() != null) {
                throw e.getCause();
            } else {
                throw e;
            }
        }
    })).build();
    Storage testStorage = storageOptions.getService();
    testStorage.create(bucketInfo);
    ByteBuffer content = dataGeneration.randByteBuffer(contentSize);
    // create a duplicate to preserve the initial offset and limit for assertion later
    ByteBuffer expected = content.duplicate();
    WriteChannel w = testStorage.writer(blobInfoGen0, BlobWriteOption.generationMatch());
    w.write(content);
    w.close();
    RetryTestResource postRunState = testBench.getRetryTest(retryTest);
    assertTrue(postRunState.completed);
    Optional<StorageObject> optionalStorageObject = PackagePrivateMethodWorkarounds.maybeGetStorageObjectFunction().apply(w);
    assertTrue(optionalStorageObject.isPresent());
    StorageObject storageObject = optionalStorageObject.get();
    assertThat(storageObject.getName()).isEqualTo(blobInfoGen0.getName());
    // construct a new blob id, without a generation, so we get the latest when we perform a get
    BlobId blobIdGen1 = BlobId.of(storageObject.getBucket(), storageObject.getName());
    Blob blobGen2 = testStorage.get(blobIdGen1);
    assertEquals(contentSize, (long) blobGen2.getSize());
    assertNotEquals(blobInfoGen0.getGeneration(), blobGen2.getGeneration());
    ByteArrayOutputStream actualData = new ByteArrayOutputStream();
    blobGen2.downloadTo(actualData);
    ByteBuffer actual = ByteBuffer.wrap(actualData.toByteArray());
    assertEquals(expected, actual);
}
Also used : DateTimeFormatter(org.threeten.bp.format.DateTimeFormatter) InstructionList(com.google.cloud.conformance.storage.v1.InstructionList) RetryTestResource(com.google.cloud.storage.conformance.retry.TestBench.RetryTestResource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NoCredentials(com.google.cloud.NoCredentials) BlobId(com.google.cloud.storage.BlobId) Random(java.util.Random) StorageOptions(com.google.cloud.storage.StorageOptions) ByteBuffer(java.nio.ByteBuffer) BlobWriteOption(com.google.cloud.storage.Storage.BlobWriteOption) Blob(com.google.cloud.storage.Blob) DataGeneration(com.google.cloud.storage.DataGeneration) TestName(org.junit.rules.TestName) ZoneOffset(org.threeten.bp.ZoneOffset) Instant(org.threeten.bp.Instant) Method(com.google.cloud.conformance.storage.v1.Method) ZoneId(org.threeten.bp.ZoneId) StorageRpc(com.google.cloud.storage.spi.v1.StorageRpc) ClassRule(org.junit.ClassRule) JsonParser(com.google.api.client.json.JsonParser) StorageObject(com.google.api.services.storage.model.StorageObject) BlobInfo(com.google.cloud.storage.BlobInfo) ImmutableMap(com.google.common.collect.ImmutableMap) BucketInfo(com.google.cloud.storage.BucketInfo) Assert.assertTrue(org.junit.Assert.assertTrue) Reflection(com.google.common.reflect.Reflection) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Logger(java.util.logging.Logger) TestBench(com.google.cloud.storage.conformance.retry.TestBench) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) FixedHeaderProvider(com.google.api.gax.rpc.FixedHeaderProvider) Rule(org.junit.Rule) Optional(java.util.Optional) WriteChannel(com.google.cloud.WriteChannel) Storage(com.google.cloud.storage.Storage) Assert.assertEquals(org.junit.Assert.assertEquals) PackagePrivateMethodWorkarounds(com.google.cloud.storage.PackagePrivateMethodWorkarounds) Clock(org.threeten.bp.Clock) Blob(com.google.cloud.storage.Blob) StorageObject(com.google.api.services.storage.model.StorageObject) BlobInfo(com.google.cloud.storage.BlobInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) StorageRpc(com.google.cloud.storage.spi.v1.StorageRpc) Storage(com.google.cloud.storage.Storage) StorageOptions(com.google.cloud.storage.StorageOptions) RetryTestResource(com.google.cloud.storage.conformance.retry.TestBench.RetryTestResource) WriteChannel(com.google.cloud.WriteChannel) BucketInfo(com.google.cloud.storage.BucketInfo) BlobId(com.google.cloud.storage.BlobId)

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