Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump nginx from 104c7c5 to 86e53c4 in /examples/local_ratelimit #838

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/local_ratelimit/Dockerfile-nginx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM nginx@sha256:add4792d930c25dd2abf2ef9ea79de578097a1c175a16ab25814332fe33622de
FROM nginx@sha256:86e53c4c16a6a276b204b0fd3a8143d86547c967dc8258b3d47c3a21bb68d3c6
13 changes: 11 additions & 2 deletions mobile/library/common/jni/jni_utility.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "library/common/jni/jni_utility.h"

#include <stdlib.h>
#include <string.h>
#include <cstdlib>
#include <cstring>

#include "source/common/common/assert.h"

Expand Down Expand Up @@ -355,6 +355,15 @@ void javaByteArrayToProto(JniHelper& jni_helper, jbyteArray source,
RELEASE_ASSERT(success, "Failed to parse protobuf message.");
}

LocalRefUniquePtr<jbyteArray> protoToJavaByteArray(JniHelper& jni_helper,
const Envoy::Protobuf::MessageLite& source) {
size_t size = source.ByteSizeLong();
LocalRefUniquePtr<jbyteArray> byte_array = jni_helper.newByteArray(size);
auto bytes = jni_helper.getByteArrayElements(byte_array.get(), nullptr);
source.SerializeToArray(bytes.get(), size);
return byte_array;
}

std::string javaStringToString(JniHelper& jni_helper, jstring java_string) {
if (!java_string) {
return "";
Expand Down
4 changes: 4 additions & 0 deletions mobile/library/common/jni/jni_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ void javaByteArrayToString(JniHelper& jni_helper, jbyteArray jbytes, std::string
void javaByteArrayToProto(JniHelper& jni_helper, jbyteArray source,
Envoy::Protobuf::MessageLite* dest);

/** Converts from Proto to Java byte array. */
LocalRefUniquePtr<jbyteArray> protoToJavaByteArray(JniHelper& jni_helper,
const Envoy::Protobuf::MessageLite& source);

/** Converts from Java `String` to C++ string. */
std::string javaStringToString(JniHelper& jni_helper, jstring java_string);

Expand Down
20 changes: 20 additions & 0 deletions mobile/test/common/jni/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,23 @@ cc_binary(
":jni_helper_test_lib",
],
)

cc_library(
name = "jni_utility_test_lib",
srcs = [
"jni_utility_test.cc",
],
deps = [
"//library/common/jni:jni_utility_lib",
],
alwayslink = True,
)

cc_binary(
name = "libenvoy_jni_utility_test.so",
testonly = True,
linkshared = True,
deps = [
":jni_utility_test_lib",
],
)
17 changes: 17 additions & 0 deletions mobile/test/common/jni/jni_utility_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <jni.h>

#include "library/common/jni/jni_utility.h"

// NOLINT(namespace-envoy)

// This file contains JNI implementation used by
// `test/java/io/envoyproxy/envoymobile/jni/JniUtilityTest.java` unit tests.

extern "C" JNIEXPORT jbyteArray JNICALL
Java_io_envoyproxy_envoymobile_jni_JniUtilityTest_protoJavaByteArrayConversion(JNIEnv* env, jclass,
jbyteArray source) {
Envoy::JNI::JniHelper jni_helper(env);
Envoy::ProtobufWkt::Struct s;
Envoy::JNI::javaByteArrayToProto(jni_helper, source, &s);
return Envoy::JNI::protoToJavaByteArray(jni_helper, s).release();
}
14 changes: 14 additions & 0 deletions mobile/test/java/io/envoyproxy/envoymobile/jni/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,17 @@ envoy_mobile_android_test(
],
native_lib_name = "envoy_jni_helper_test",
)

envoy_mobile_android_test(
name = "jni_utility_test",
srcs = [
"JniUtilityTest.java",
],
native_deps = [
"//test/common/jni:libenvoy_jni_utility_test.so",
],
native_lib_name = "envoy_jni_utility_test",
deps = [
"@maven//:com_google_protobuf_protobuf_javalite",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.envoyproxy.envoymobile.jni;

import static org.assertj.core.api.Assertions.assertThat;

import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class JniUtilityTest {
public JniUtilityTest() { System.loadLibrary("envoy_jni_utility_test"); }

//================================================================================
// Native methods for testing.
//================================================================================
public static native byte[] protoJavaByteArrayConversion(byte[] source);

@Test
public void testProtoJavaByteArrayConversion() throws Exception {
Struct source =
Struct.newBuilder()
.putFields("string_key", Value.newBuilder().setStringValue("string_value").build())
.putFields("num_key", Value.newBuilder().setNumberValue(123).build())
.putFields("bool_key", Value.newBuilder().setBoolValue(true).build())
.build();
Struct dest = Struct.parseFrom(protoJavaByteArrayConversion(source.toByteArray()));
assertThat(source).isEqualTo(dest);
}
}