@@ -11,50 +11,59 @@ const crypto = require('crypto');
1111const fs = require ( 'fs' ) ;
1212const path = require ( 'path' ) ;
1313
14+ // Engine support in OpenSSL is checked later on.
15+ let hasEngineSupport = true ;
1416
15- assert . throws ( ( ) => crypto . setEngine ( true ) , / E R R _ I N V A L I D _ A R G _ T Y P E / ) ;
17+ assert . throws ( ( ) => crypto . setEngine ( true ) , / E R R _ I N V A L I D _ A R G _ T Y P E | E R R _ C R Y P T O _ C U S T O M _ E N G I N E _ N O T _ S U P P O R T E D / ) ;
1618assert . throws ( ( ) => crypto . setEngine ( '/path/to/engine' , 'notANumber' ) ,
1719 / E R R _ I N V A L I D _ A R G _ T Y P E / ) ;
1820
1921{
2022 const invalidEngineName = 'xxx' ;
2123 assert . throws ( ( ) => crypto . setEngine ( invalidEngineName ) ,
22- / E R R _ C R Y P T O _ E N G I N E _ U N K N O W N / ) ;
24+ / E R R _ C R Y P T O _ E N G I N E _ U N K N O W N | E R R _ C R Y P T O _ C U S T O M _ E N G I N E _ N O T _ S U P P O R T E D / ) ;
2325 assert . throws ( ( ) => crypto . setEngine ( invalidEngineName ,
2426 crypto . constants . ENGINE_METHOD_RSA ) ,
25- / E R R _ C R Y P T O _ E N G I N E _ U N K N O W N / ) ;
27+ / E R R _ C R Y P T O _ E N G I N E _ U N K N O W N | E R R _ C R Y P T O _ C U S T O M _ E N G I N E _ N O T _ S U P P O R T E D / ) ;
2628}
2729
28- crypto . setEngine ( 'dynamic' ) ;
29- crypto . setEngine ( 'dynamic' ) ;
30+ try {
31+ crypto . setEngine ( 'dynamic' ) ;
32+ crypto . setEngine ( 'dynamic' ) ;
3033
31- crypto . setEngine ( 'dynamic' , crypto . constants . ENGINE_METHOD_RSA ) ;
32- crypto . setEngine ( 'dynamic' , crypto . constants . ENGINE_METHOD_RSA ) ;
34+ crypto . setEngine ( 'dynamic' , crypto . constants . ENGINE_METHOD_RSA ) ;
35+ crypto . setEngine ( 'dynamic' , crypto . constants . ENGINE_METHOD_RSA ) ;
36+ } catch ( err ) {
37+ assert . strictEqual ( err . code , 'ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED' ) ;
38+ hasEngineSupport = false ;
39+ }
3340
34- const engine = path . join ( __dirname ,
35- `/build/${ common . buildType } /testsetengine.engine` ) ;
41+ if ( hasEngineSupport ) {
42+ const engine = path . join ( __dirname ,
43+ `/build/${ common . buildType } /testsetengine.engine` ) ;
3644
37- if ( ! fs . existsSync ( engine ) )
38- common . skip ( 'no engine' ) ;
45+ if ( ! fs . existsSync ( engine ) )
46+ common . skip ( 'no engine' ) ;
3947
40- {
41- const engineId = path . parse ( engine ) . name ;
42- const execDir = path . parse ( engine ) . dir ;
48+ {
49+ const engineId = path . parse ( engine ) . name ;
50+ const execDir = path . parse ( engine ) . dir ;
4351
44- crypto . setEngine ( engine ) ;
45- // OpenSSL 3.0.1 and 1.1.1m now throw errors if an engine is loaded again
46- // with a duplicate absolute path.
47- // TODO(richardlau): figure out why this fails on macOS but not Linux.
48- // crypto.setEngine(engine);
52+ crypto . setEngine ( engine ) ;
53+ // OpenSSL 3.0.1 and 1.1.1m now throw errors if an engine is loaded again
54+ // with a duplicate absolute path.
55+ // TODO(richardlau): figure out why this fails on macOS but not Linux.
56+ // crypto.setEngine(engine);
4957
50- // crypto.setEngine(engine, crypto.constants.ENGINE_METHOD_RSA);
51- // crypto.setEngine(engine, crypto.constants.ENGINE_METHOD_RSA);
58+ // crypto.setEngine(engine, crypto.constants.ENGINE_METHOD_RSA);
59+ // crypto.setEngine(engine, crypto.constants.ENGINE_METHOD_RSA);
5260
53- process . env . OPENSSL_ENGINES = execDir ;
61+ process . env . OPENSSL_ENGINES = execDir ;
5462
55- crypto . setEngine ( engineId ) ;
56- crypto . setEngine ( engineId ) ;
63+ crypto . setEngine ( engineId ) ;
64+ crypto . setEngine ( engineId ) ;
5765
58- crypto . setEngine ( engineId , crypto . constants . ENGINE_METHOD_RSA ) ;
59- crypto . setEngine ( engineId , crypto . constants . ENGINE_METHOD_RSA ) ;
66+ crypto . setEngine ( engineId , crypto . constants . ENGINE_METHOD_RSA ) ;
67+ crypto . setEngine ( engineId , crypto . constants . ENGINE_METHOD_RSA ) ;
68+ }
6069}
0 commit comments