From bbc17d763ddf5d478a392d0830c064b5f8c750b9 Mon Sep 17 00:00:00 2001 From: Mike Danese Date: Wed, 20 Feb 2019 21:29:54 -0800 Subject: [PATCH 1/2] update bazel build to latest version of bazel * explicitly load git_repository rule * load googletest as a git_repository * stop using bind (see https://github.com/bazelbuild/bazel/issues/1952) --- WORKSPACE | 22 +- core/BUILD | 12 +- cpp/BUILD | 2 +- gmock.BUILD | 605 ---------------------------------------------------- 4 files changed, 10 insertions(+), 631 deletions(-) delete mode 100644 gmock.BUILD diff --git a/WORKSPACE b/WORKSPACE index 235c7bb2e..0e1a841a0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,11 +1,6 @@ workspace(name = "jsonnet") -# This local_repository looks silly but it makes io_bazel_rules_jsonnet use -# _this_ jsonnet, not another downloaded copy. -local_repository( - name = "jsonnet", - path = ".", -) +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") git_repository( name = "io_bazel_rules_jsonnet", @@ -13,23 +8,12 @@ git_repository( remote = "https://github.com/bazelbuild/rules_jsonnet.git", ) -new_git_repository( +git_repository( name = "com_google_googletest", remote = "https://github.com/google/googletest.git", # If updating googletest version, also update CMakeLists.txt.in. - tag = "release-1.8.0", - build_file = "gmock.BUILD", -) - -bind( - name = "googletest", - actual = "@com_google_googletest//:googletest_no_main", -) - -bind( - name = "googletest_main", - actual = "@com_google_googletest//:googletest", + tag = "release-1.8.1", ) load("//tools/build_defs:python_repo.bzl", "python_interpreter") diff --git a/core/BUILD b/core/BUILD index 70594ac8a..6a0e9cb50 100644 --- a/core/BUILD +++ b/core/BUILD @@ -28,15 +28,15 @@ cc_library( "unicode.h", "vm.h", ], + includes = ["."], + linkopts = ["-lm"], deps = [ "//include:libjsonnet", "//include:libjsonnet_fmt", "//stdlib:std", - "//third_party/json:json", + "//third_party/json", "//third_party/md5:libmd5", ], - linkopts = ["-lm"], - includes = ["."], ) cc_test( @@ -45,7 +45,7 @@ cc_test( deps = [ ":libjsonnet", # Note: On Ubuntu, apt-get install libgtest-dev google-mock - "//external:googletest_main", + "@com_google_googletest//:gtest_main", ], ) @@ -54,7 +54,7 @@ cc_test( srcs = ["parser_test.cpp"], deps = [ ":libjsonnet", - "//external:googletest_main", + "@com_google_googletest//:gtest_main", ], ) @@ -63,6 +63,6 @@ cc_test( srcs = ["libjsonnet_test.cpp"], deps = [ ":libjsonnet", - "//external:googletest_main", + "@com_google_googletest//:gtest_main", ], ) diff --git a/cpp/BUILD b/cpp/BUILD index b2be1ea8c..6c8266c41 100644 --- a/cpp/BUILD +++ b/cpp/BUILD @@ -15,6 +15,6 @@ cc_test( data = ["//cpp/testdata"], deps = [ ":libjsonnet++", - "//external:googletest_main", + "@com_google_googletest//:gtest_main", ], ) diff --git a/gmock.BUILD b/gmock.BUILD deleted file mode 100644 index 1c4f98c65..000000000 --- a/gmock.BUILD +++ /dev/null @@ -1,605 +0,0 @@ -# BUILD file borrowed from https://github.com/google/googletest/pull/581/files - -package(default_visibility = ["//visibility:public"]) -licenses(["notice"]) - -cc_library( - name = "googletest", - srcs = ["googletest/src/gtest_main.cc"], - deps = [ - ":googletest_no_main", - ], -) - -cc_library( - name = "googletest_no_main", - srcs = glob([ - "googletest/src/gtest.cc", - "googletest/src/gtest-death-test.cc", - "googletest/src/gtest-filepath.cc", - "googletest/src/gtest-internal-inl.h", - "googletest/src/gtest-port.cc", - "googletest/src/gtest-printers.cc", - "googletest/src/gtest-test-part.cc", - "googletest/src/gtest-typed-test.cc", - "googletest/include/gtest/internal/*.h", - "googletest/include/gtest/internal/custom/*.h", - ]), - hdrs = glob([ - "googletest/include/gtest/*.h" - ]), - includes = [ - "googletest", - "googletest/include", - ], - copts = [ - "-g", - "-Wall", - "-Wextra", - "-pthread", - ], - linkopts = [ - "-pthread", - ], -) - -cc_library( - name = "googlemock", - srcs = glob([ - "googlemock/src/gmock-cardinalities.cc", - "googlemock/src/gmock.cc", - "googlemock/src/gmock-internal-utils.cc", - "googlemock/src/gmock_main.cc", - "googlemock/src/gmock-matchers.cc", - "googlemock/src/gmock-spec-builders.cc", - "googlemock/include/gmock/internal/*.h", - "googlemock/include/gmock/internal/custom/*.h", - ]), - hdrs = glob([ - "googlemock/include/gmock/*.h" - ]), - includes = [ - "googlemock", - "googlemock/include", - ], - copts = [ - "-std=c++11", - "-g", - "-Wall", - "-Wextra", - ], - linkopts = [ - "-pthread", - ], - deps = [ - ":googletest", - ], -) - -cc_library( - name = "googletest_sample_libs", - hdrs = [ - "googletest/samples/prime_tables.h", - "googletest/samples/sample1.h", - "googletest/samples/sample2.h", - "googletest/samples/sample3-inl.h", - "googletest/samples/sample4.h", - ], - srcs = [ - "googletest/samples/sample1.cc", - "googletest/samples/sample2.cc", - "googletest/samples/sample4.cc", - ], -) - -test_suite( - name = "googletest_example_tests", - tests = [ - ":googletest_sample1_test", - ":googletest_sample2_test", - ":googletest_sample3_test", - ":googletest_sample4_test", - ":googletest_sample5_test", - ":googletest_sample6_test", - ":googletest_sample7_test", - ":googletest_sample8_test", - ":googletest_sample9_test", - ":googletest_sample10_test", - ], -) - -test_suite( - name = "googletest_tests", - tests = [ - ":googletest_gtest_filepath_test", - ":googletest_gtest_linked_ptr_test", - ":googletest_gtest_message_test", - # The gtest_options_test fails when run as a test suite since it - # uses a hard-coded binary name. - # ":googletest_gtest_options_test", - ":googletest_gtest_port_test", - ":googletest_gtest_pred_impl_unittest", - ":googletest_gtest_prod_test", - ":googletest_gtest_test_part_test", - ":googletest_gtest_typed_test_test", - ":googletest_gtest_typed_test2_test", - ":googletest_gtest_unittest", - ":googletest_gtest_production_test", - ], -) - -test_suite( - name = "googlemock_tests", - tests = [ - ":googlemock_gmock_actions_test", - ":googlemock_gmock_cardinalities_test", - ":googlemock_gmock_ex_test", - ":googlemock_gmock_generated_actions_test", - ":googlemock_gmock-generated_function_mockers_test", - ":googlemock_gmock-generated_internal_utils_test", - ":googlemock_gmock-generated_matchers_test", - ":googlemock_gmock_internal_utils_test", - # ":googlemock_gmock_leak_test", - ":googlemock_gmock_link_test", - ":googlemock_gmock_link2_test", - ":googlemock_gmock_matchers_test", - ":googlemock_gmock_more_actions_test", - ":googlemock_gmock_nice_strict_test", - # ":googlemock_gmock_output_test", - ":googlemock_gmock_port_test", - ":googlemock_gmock_spec_builders_test", - ":googlemock_gmock_stress_test", - ":googlemock_gmock_test", - ], -) - -cc_test( - name = "googletest_sample1_test", - srcs = ["googletest/samples/sample1_unittest.cc"], - deps = [ - ":googletest_sample_libs", - ":googletest", - ], -) - -cc_test( - name = "googletest_sample2_test", - srcs = ["googletest/samples/sample2_unittest.cc"], - deps = [ - ":googletest", - ":googletest_sample_libs", - ], -) - -cc_test( - name = "googletest_sample3_test", - srcs = ["googletest/samples/sample3_unittest.cc"], - deps = [ - ":googletest", - ":googletest_sample_libs", - ], -) - -cc_test( - name = "googletest_sample4_test", - srcs = ["googletest/samples/sample4_unittest.cc"], - deps = [ - ":googletest", - ":googletest_sample_libs", - ], -) - -cc_test( - name = "googletest_sample5_test", - srcs = ["googletest/samples/sample5_unittest.cc"], - deps = [ - ":googletest", - ":googletest_sample_libs", - ], -) - -cc_test( - name = "googletest_sample6_test", - srcs = ["googletest/samples/sample6_unittest.cc"], - deps = [ - ":googletest", - ":googletest_sample_libs", - ], -) - -cc_test( - name = "googletest_sample7_test", - srcs = ["googletest/samples/sample7_unittest.cc"], - deps = [ - ":googletest", - ":googletest_sample_libs", - ], -) - -cc_test( - name = "googletest_sample8_test", - srcs = ["googletest/samples/sample8_unittest.cc"], - deps = [ - ":googletest", - ":googletest_sample_libs", - ], -) - -cc_test( - name = "googletest_sample9_test", - srcs = ["googletest/samples/sample9_unittest.cc"], - deps = [ - ":googletest", - ":googletest_sample_libs", - ], -) - -cc_test( - name = "googletest_sample10_test", - srcs = ["googletest/samples/sample10_unittest.cc"], - deps = [ - ":googletest", - ":googletest_sample_libs", - ], -) - -""" Tests on the googletest library itself.""" -cc_library( - name = "gtest_production", - hdrs = [ - "googletest/test/production.h", - ], - srcs = [ - "googletest/test/production.cc", - ], - deps = [ - ":googletest", - ], -) - -cc_test( - name = "googletest_gtest_filepath_test", - srcs = [ - "googletest/test/gtest-filepath_test.cc", - ], - deps = [ - ":googletest", - ], -) - -cc_test( - name = "googletest_gtest_linked_ptr_test", - srcs = [ - "googletest/test/gtest-linked_ptr_test.cc", - ], - deps = [ - ":googletest", - ], -) - -cc_test( - name = "googletest_gtest_message_test", - srcs = [ - "googletest/test/gtest-message_test.cc", - ], - deps = [ - ":googletest", - ], -) - -""" -This test currently fails based on how the test itself checks for the running executable -name. - -cc_test( - name = "googletest_gtest_options_test", - srcs = [ - "googletest/test/gtest-options_test.cc", - ], - deps = [ - ":googletest", - ], -)""" - -cc_test( - name = "googletest_gtest_port_test", - srcs = [ - "googletest/test/gtest-port_test.cc", - ], - deps = [ - ":googletest", - ], -) - -cc_test( - name = "googletest_gtest_pred_impl_unittest", - srcs = [ - "googletest/test/gtest_pred_impl_unittest.cc", - ], - deps = [ - ":googletest", - ], -) - -cc_test( - name = "googletest_gtest_prod_test", - srcs = [ - "googletest/test/gtest_prod_test.cc", - ], - includes = [ - "googletest", - "googletest/include", - ], - deps = [ - ":googletest", - ":gtest_production", - ], -) - -cc_test( - name = "googletest_gtest_test_part_test", - srcs = [ - "googletest/test/gtest-test-part_test.cc", - ], - deps = [ - ":googletest", - ], -) - -cc_test( - name = "googletest_gtest_typed_test_test", - srcs = [ - "googletest/test/gtest-typed-test_test.cc", - ], - deps = [ - ":googletest", - ], -) - -cc_test( - name = "googletest_gtest_typed_test2_test", - srcs = [ - "googletest/test/gtest-typed-test2_test.cc", - ], - deps = [ - ":googletest", - ], -) - -cc_test( - name = "googletest_gtest_unittest", - srcs = [ - "googletest/test/gtest_unittest.cc", - ], - deps = [ - ":googletest", - ], -) - -cc_test( - name = "googletest_gtest_production_test", - srcs = [ - "googletest/test/production.cc", - ], - deps = [ - ":googletest", - ], -) - -""" Tests on the googlemock library itself.""" -cc_test( - name = "googlemock_gmock_actions_test", - srcs = [ - "googlemock/test/gmock-actions_test.cc", - ], - copts = [ - "-std=c++11", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock_cardinalities_test", - srcs = [ - "googlemock/test/gmock-cardinalities_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock_ex_test", - srcs = [ - "googlemock/test/gmock_ex_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock_generated_actions_test", - srcs = [ - "googlemock/test/gmock-generated-actions_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock-generated_function_mockers_test", - srcs = [ - "googlemock/test/gmock-generated-function-mockers_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock-generated_internal_utils_test", - srcs = [ - "googlemock/test/gmock-generated-internal-utils_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock-generated_matchers_test", - srcs = [ - "googlemock/test/gmock-generated-matchers_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock_internal_utils_test", - srcs = [ - "googlemock/test/gmock-internal-utils_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -""" -This test currently runs through the python component and fails on its own. -cc_test( - name = "googlemock_gmock_leak_test", - srcs = [ - "googlemock/test/gmock_leak_test_.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -)""" - -cc_test( - name = "googlemock_gmock_link_test", - srcs = [ - "googlemock/test/gmock_link_test.h", - "googlemock/test/gmock_link_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock_link2_test", - srcs = [ - "googlemock/test/gmock_link2_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock_matchers_test", - srcs = [ - "googlemock/test/gmock-matchers_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock_more_actions_test", - srcs = [ - "googlemock/test/gmock-more-actions_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock_nice_strict_test", - srcs = [ - "googlemock/test/gmock-nice-strict_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -""" -This test is currently run through the python component and fails on its own. -cc_test( - name = "googlemock_gmock_output_test", - srcs = [ - "googlemock/test/gmock_output_test_.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -)""" - -cc_test( - name = "googlemock_gmock_port_test", - srcs = [ - "googlemock/test/gmock-port_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock_spec_builders_test", - srcs = [ - "googlemock/test/gmock-spec-builders_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock_stress_test", - srcs = [ - "googlemock/test/gmock_stress_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) - -cc_test( - name = "googlemock_gmock_test", - srcs = [ - "googlemock/test/gmock_test.cc", - ], - deps = [ - ":googlemock", - ":googletest", - ], -) From 93ae8602bb17dc06c9160b658d59862e7a14316f Mon Sep 17 00:00:00 2001 From: Mike Danese Date: Wed, 20 Feb 2019 22:47:37 -0800 Subject: [PATCH 2/2] implement std.sha256 --- Makefile | 8 ++++---- WORKSPACE | 12 ++++++++++++ core/BUILD | 17 ++++++++++++++++- core/desugarer.cpp | 3 ++- core/hash.cpp | 35 +++++++++++++++++++++++++++++++++++ core/hash.h | 13 +++++++++++++ core/vm.cpp | 25 +++++++++++++++++++++++-- test_suite/stdlib.jsonnet | 7 +++++++ 8 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 core/hash.cpp create mode 100644 core/hash.h diff --git a/Makefile b/Makefile index 159c1aa00..9df4c0a1e 100644 --- a/Makefile +++ b/Makefile @@ -29,9 +29,9 @@ OD ?= od OPT ?= -O3 -CXXFLAGS ?= -g $(OPT) -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json +CXXFLAGS ?= -g $(OPT) -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/json CFLAGS ?= -g $(OPT) -Wall -Wextra -pedantic -std=c99 -fPIC -Iinclude -MAKEDEPENDFLAGS ?= -Iinclude -Ithird_party/md5 -Ithird_party/json +MAKEDEPENDFLAGS ?= -Iinclude -Ithird_party/json EMCXXFLAGS = $(CXXFLAGS) -g0 -Os --memory-init-file 0 -s DISABLE_EXCEPTION_CATCHING=0 -s OUTLINING_LIMIT=10000 -s RESERVED_FUNCTION_POINTERS=20 EMCFLAGS = $(CFLAGS) --memory-init-file 0 -s DISABLE_EXCEPTION_CATCHING=0 LDFLAGS ?= @@ -52,7 +52,7 @@ LIB_SRC = \ core/static_analysis.cpp \ core/string_utils.cpp \ core/vm.cpp \ - third_party/md5/md5.cpp + hash/hash.cpp LIB_OBJ = $(LIB_SRC:.cpp=.o) @@ -83,10 +83,10 @@ ALL_HEADERS = \ core/string_utils.h \ core/vm.h \ core/std.jsonnet.h \ + hash/hash.h \ include/libjsonnet.h \ include/libjsonnet_fmt.h \ include/libjsonnet++.h \ - third_party/md5/md5.h \ third_party/json/json.hpp default: jsonnet diff --git a/WORKSPACE b/WORKSPACE index 0e1a841a0..5e5667b5a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,6 +16,18 @@ git_repository( tag = "release-1.8.1", ) +git_repository( + name = "boringssl", + commit = "b8a5219531146b0907a72da8e62f331bb0d673c5", + remote = "https://boringssl.googlesource.com/boringssl", +) + +git_repository( + name = "com_google_absl", + commit = "2a62fbdedf64673f7c858bc6487bd15bcd2ca180", + remote = "https://github.com/abseil/abseil-cpp.git", +) + load("//tools/build_defs:python_repo.bzl", "python_interpreter") python_interpreter(name = "default_python") diff --git a/core/BUILD b/core/BUILD index 6a0e9cb50..b9c8fac1a 100644 --- a/core/BUILD +++ b/core/BUILD @@ -31,11 +31,11 @@ cc_library( includes = ["."], linkopts = ["-lm"], deps = [ + ":hash", "//include:libjsonnet", "//include:libjsonnet_fmt", "//stdlib:std", "//third_party/json", - "//third_party/md5:libmd5", ], ) @@ -66,3 +66,18 @@ cc_test( "@com_google_googletest//:gtest_main", ], ) + +cc_library( + name = "hash", + srcs = [ + "hash.cpp", + ], + hdrs = [ + "hash.h", + ], + visibility = ["//visibility:private"], + deps = [ + "@boringssl//:crypto", + "@com_google_absl//absl/strings", + ], +) diff --git a/core/desugarer.cpp b/core/desugarer.cpp index 1cd45a0d6..0c96d5b68 100644 --- a/core/desugarer.cpp +++ b/core/desugarer.cpp @@ -34,7 +34,7 @@ struct BuiltinDecl { std::vector params; }; -static unsigned long max_builtin = 37; +static unsigned long max_builtin = 38; BuiltinDecl jsonnet_builtin_decl(unsigned long builtin) { switch (builtin) { @@ -76,6 +76,7 @@ BuiltinDecl jsonnet_builtin_decl(unsigned long builtin) case 35: return {U"parseJson", {U"str"}}; case 36: return {U"encodeUTF8", {U"str"}}; case 37: return {U"decodeUTF8", {U"arr"}}; + case 38: return {U"sha256", {U"str"}}; default: std::cerr << "INTERNAL ERROR: Unrecognized builtin function: " << builtin << std::endl; std::abort(); diff --git a/core/hash.cpp b/core/hash.cpp new file mode 100644 index 000000000..4f9b579ff --- /dev/null +++ b/core/hash.cpp @@ -0,0 +1,35 @@ +#include "core/hash.h" + +#include "absl/strings/escaping.h" +#include "openssl/bio.h" +#include "openssl/digest.h" + +namespace jsonnet { +namespace hash { + +namespace { + +std::string digest(const std::string& input, const EVP_MD* alg) +{ + uint8_t digest[EVP_MAX_MD_SIZE]; + unsigned int digest_length = 0; + if (EVP_Digest(input.data(), input.size(), digest, &digest_length, alg, nullptr) != 1) { + return ""; + } + return absl::BytesToHexString( + std::string(reinterpret_cast(digest), digest_length)); +} +} // namespace + +std::string Sha256(const std::string& input) +{ + return digest(input, EVP_sha256()); +} + +std::string Md5(const std::string& input) +{ + return digest(input, EVP_md5()); +} + +} // namespace hash +} // namespace jsonnet diff --git a/core/hash.h b/core/hash.h new file mode 100644 index 000000000..97327f17a --- /dev/null +++ b/core/hash.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace jsonnet { +namespace hash { + +std::string Sha256(const std::string& input); + +std::string Md5(const std::string& input); + +} // namespace hash +} // namespace jsonnet diff --git a/core/vm.cpp b/core/vm.cpp index 5bb9cab33..6e0725cc1 100644 --- a/core/vm.cpp +++ b/core/vm.cpp @@ -21,10 +21,10 @@ limitations under the License. #include #include +#include "core/hash.h" #include "desugarer.h" #include "json.h" #include "json.hpp" -#include "md5.h" #include "parser.h" #include "state.h" #include "static_analysis.h" @@ -869,7 +869,12 @@ class Interpreter { builtins["extVar"] = &Interpreter::builtinExtVar; builtins["primitiveEquals"] = &Interpreter::builtinPrimitiveEquals; builtins["native"] = &Interpreter::builtinNative; +#ifndef DISABLE_INSECURE_HASH builtins["md5"] = &Interpreter::builtinMd5; +#else + builtins["md5"] = &Interpreter::builtinMd5Disabled; +#endif + builtins["sha256"] = &Interpreter::builtinSha256; builtins["trace"] = &Interpreter::builtinTrace; builtins["splitLimit"] = &Interpreter::builtinSplitLimit; builtins["substr"] = &Interpreter::builtinSubstr; @@ -1310,7 +1315,23 @@ class Interpreter { std::string value = encode_utf8(static_cast(args[0].v.h)->value); - scratch = makeString(decode_utf8(md5(value))); + scratch = makeString(decode_utf8(jsonnet::hash::Md5(value))); + return nullptr; + } + + const AST *builtinMd5Disabled(const LocationRange &loc, const std::vector &args) + { + throw makeError( + loc, "std.md5 was disabled at compile time because it is insecure. Use std.sha256."); + } + + const AST *builtinSha256(const LocationRange &loc, const std::vector &args) + { + validateBuiltinArgs(loc, "sha255", args, {Value::STRING}); + + std::string value = encode_utf8(static_cast(args[0].v.h)->value); + + scratch = makeString(decode_utf8(jsonnet::hash::Sha256(value))); return nullptr; } diff --git a/test_suite/stdlib.jsonnet b/test_suite/stdlib.jsonnet index cdf32f2b8..9dd86b772 100644 --- a/test_suite/stdlib.jsonnet +++ b/test_suite/stdlib.jsonnet @@ -839,6 +839,13 @@ std.assertEqual(std.md5(''), 'd41d8cd98f00b204e9800998ecf8427e') && std.assertEqual(std.md5('grape'), 'b781cbb29054db12f88f08c6e161c199') && std.assertEqual(std.md5("{}[]01234567890\"'+=-_/<>?,.!@#$%^&*|\\:;`~"), 'a680db28332f0c9647376e5b2aeb4b3d') && std.assertEqual(std.md5('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum si.'), '3496bb633e830e7679ce53700d42de1e') && + +// verified by running values through sha256sum +std.assertEqual(std.sha256(''), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855') && +std.assertEqual(std.sha256('grape'), '0f78fcc486f5315418fbf095e71c0675ee07d318e5ac4d150050cd8e57966496') && +std.assertEqual(std.sha256("{}[]01234567890\"'+=-_/<>?,.!@#$%^&*|\\:;`~"), 'b9f5d5c54339ec38cb755d89482f27b0588b24dff5e584abd5c9b8d34395a454') && +std.assertEqual(std.sha256('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum si.'), 'ed427039cad3a77cea97a92d696622121e08f67657c7f887076529b4bf37963d') && + std.assertEqual(std.parseInt('-01234567890'), -1234567890) && std.assertEqual(std.prune({}), {}) &&