File: test_node_crypto_env.cc

package info (click to toggle)
nodejs 20.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 219,072 kB
  • sloc: cpp: 1,277,408; javascript: 565,332; ansic: 129,476; python: 58,536; sh: 3,841; makefile: 2,725; asm: 1,732; perl: 248; lisp: 222; xml: 42
file content (32 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "crypto/crypto_bio.h"
#include "gtest/gtest.h"
#include "node_options.h"
#include "node_test_fixture.h"
#include "openssl/err.h"

using v8::Local;
using v8::String;

/*
 * This test verifies that an object created by LoadBIO supports BIO_tell
 * and BIO_seek, otherwise PEM_read_bio_PrivateKey fails on some keys
 * (if OpenSSL needs to rewind pointer between pem_read_bio_key()
 * and pem_read_bio_key_legacy() inside PEM_read_bio_PrivateKey).
 */
class NodeCryptoEnv : public EnvironmentTestFixture {};

TEST_F(NodeCryptoEnv, LoadBIO) {
  v8::HandleScope handle_scope(isolate_);
  Argv argv;
  Env env{handle_scope, argv};
  //  just put a random string into BIO
  Local<String> key = String::NewFromUtf8(isolate_, "abcdef").ToLocalChecked();
  node::crypto::BIOPointer bio(node::crypto::LoadBIO(*env, key));
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  const int ofs = 2;
  ASSERT_EQ(BIO_seek(bio.get(), ofs), ofs);
  ASSERT_EQ(BIO_tell(bio.get()), ofs);
#endif
  ASSERT_EQ(ERR_peek_error(), 0UL) << "There should not have left "
                                      "any errors on the OpenSSL error stack\n";
}