diff options
author | Nicolas Noble <nicolasnoble@users.noreply.github.com> | 2015-07-01 09:26:21 -0700 |
---|---|---|
committer | Nicolas Noble <nicolasnoble@users.noreply.github.com> | 2015-07-01 09:26:21 -0700 |
commit | 6ab0de15ea219594c702ed1e497ec8b157239c66 (patch) | |
tree | 4e317d8620661aeedaa02ee0a8a4f57c44dcd575 /test/core/security | |
parent | 8993307137821dfea441fa69c31b57c4a6b7baf8 (diff) | |
parent | 73d8b57a6cea0875af0ccdd34a81f7b7c8822adf (diff) |
Merge pull request #2216 from jboeuf/unpadded_base64
Base64 decode improvements
Diffstat (limited to 'test/core/security')
-rw-r--r-- | test/core/security/base64_test.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/core/security/base64_test.c b/test/core/security/base64_test.c index a922896bc3..f8b7ebf554 100644 --- a/test/core/security/base64_test.c +++ b/test/core/security/base64_test.c @@ -169,6 +169,43 @@ static void test_rfc4648_test_vectors(void) { gpr_free(b64); } +static void test_unpadded_decode(void) { + gpr_slice decoded; + + decoded = grpc_base64_decode("Zm9vYmFy", 0); + GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded)); + GPR_ASSERT(gpr_slice_str_cmp(decoded, "foobar") == 0); + gpr_slice_unref(decoded); + + decoded = grpc_base64_decode("Zm9vYmE", 0); + GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded)); + GPR_ASSERT(gpr_slice_str_cmp(decoded, "fooba") == 0); + gpr_slice_unref(decoded); + + decoded = grpc_base64_decode("Zm9vYg", 0); + GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded)); + GPR_ASSERT(gpr_slice_str_cmp(decoded, "foob") == 0); + gpr_slice_unref(decoded); + + decoded = grpc_base64_decode("Zm9v", 0); + GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded)); + GPR_ASSERT(gpr_slice_str_cmp(decoded, "foo") == 0); + gpr_slice_unref(decoded); + + decoded = grpc_base64_decode("Zm8", 0); + GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded)); + GPR_ASSERT(gpr_slice_str_cmp(decoded, "fo") == 0); + gpr_slice_unref(decoded); + + decoded = grpc_base64_decode("Zg", 0); + GPR_ASSERT(!GPR_SLICE_IS_EMPTY(decoded)); + GPR_ASSERT(gpr_slice_str_cmp(decoded, "f") == 0); + gpr_slice_unref(decoded); + + decoded = grpc_base64_decode("", 0); + GPR_ASSERT(GPR_SLICE_IS_EMPTY(decoded)); +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); test_simple_encode_decode_b64_no_multiline(); @@ -181,5 +218,6 @@ int main(int argc, char **argv) { test_full_range_encode_decode_b64_urlsafe_multiline(); test_url_safe_unsafe_mismtach_failure(); test_rfc4648_test_vectors(); + test_unpadded_decode(); return 0; } |