1
- import test , { Test } from "tape-promise/tape" ;
2
1
import { v4 as uuidv4 } from "uuid" ;
3
-
2
+ import "jest-extended" ;
4
3
import {
5
4
ApiServer ,
6
5
AuthorizationProtocol ,
7
6
ConfigService ,
8
7
} from "../../../main/typescript/public-api" ;
9
-
10
8
import {
11
9
CactusKeychainVaultServer ,
12
10
Containers ,
@@ -23,93 +21,97 @@ import {
23
21
} from "@hyperledger/cactus-core-api" ;
24
22
import path from "path" ;
25
23
26
- test ( "NodeJS API server + Rust plugin work together" , async ( t : Test ) => {
24
+ const testCase = "NodeJS API server + Rust plugin work together" ;
25
+ describe ( testCase , ( ) => {
26
+ let apiServer : ApiServer ,
27
+ pluginContainer : CactusKeychainVaultServer ,
28
+ apiClient : DefaultApi ;
27
29
const vaultTestContainer = new VaultTestServer ( { } ) ;
28
- await vaultTestContainer . start ( ) ;
29
-
30
- const ci = await Containers . getById ( vaultTestContainer . containerId ) ;
31
- const vaultIpAddr = await Containers . getContainerInternalIp ( ci ) ;
32
- t . comment ( `Container VaultTestServer has IPv4: ${ vaultIpAddr } ` ) ;
33
30
34
- test . onFinish ( async ( ) => {
35
- await vaultTestContainer . stop ( ) ;
36
- await vaultTestContainer . destroy ( ) ;
37
- } ) ;
38
-
39
- const hostPortVault = await vaultTestContainer . getHostPortHttp ( ) ;
40
- t . comment ( `Container VaultTestServer (Port=${ hostPortVault } ) started OK` ) ;
41
- const vaultHost = `http://${ vaultIpAddr } :${ K_DEFAULT_VAULT_HTTP_PORT } ` ;
42
-
43
- const pluginContainer = new CactusKeychainVaultServer ( {
44
- envVars : [
45
- `VAULT_HOST=${ vaultHost } ` ,
46
- `VAULT_TOKEN=${ K_DEFAULT_VAULT_DEV_ROOT_TOKEN } ` ,
47
- "HOST=0.0.0.0:8080" ,
48
- ] ,
49
- } ) ;
50
- await pluginContainer . start ( ) ;
31
+ afterAll ( ( ) => apiServer . shutdown ( ) ) ;
51
32
52
- test . onFinish ( async ( ) => {
33
+ afterAll ( async ( ) => {
53
34
await pluginContainer . stop ( ) ;
54
35
await pluginContainer . destroy ( ) ;
55
36
} ) ;
56
37
57
- const hostPort = await pluginContainer . getHostPortHttp ( ) ;
58
- t . comment ( `CactusKeychainVaultServer (Port=${ hostPort } ) started OK` ) ;
59
-
60
- const configuration = new Configuration ( {
61
- basePath : `http://localhost:${ hostPort } ` ,
38
+ afterAll ( async ( ) => {
39
+ await vaultTestContainer . stop ( ) ;
40
+ await vaultTestContainer . destroy ( ) ;
62
41
} ) ;
63
- const apiClient = new DefaultApi ( configuration ) ;
64
-
65
- const pluginsPath = path . join (
66
- __dirname , // start at the current file's path
67
- "../../../../../../" , // walk back up to the project root
68
- ".tmp/test/cmd-api-server/remote-plugin-imports_test" , // the dir path from the root
69
- uuidv4 ( ) , // then a random directory to ensure proper isolation
70
- ) ;
71
- const pluginManagerOptionsJson = JSON . stringify ( { pluginsPath } ) ;
72
-
73
- const configService = new ConfigService ( ) ;
74
- const apiServerOptions = await configService . newExampleConfig ( ) ;
75
- apiServerOptions . authorizationProtocol = AuthorizationProtocol . NONE ;
76
- apiServerOptions . pluginManagerOptionsJson = pluginManagerOptionsJson ;
77
- apiServerOptions . configFile = "" ;
78
- apiServerOptions . apiCorsDomainCsv = "*" ;
79
- apiServerOptions . apiPort = 0 ;
80
- apiServerOptions . cockpitPort = 0 ;
81
- apiServerOptions . grpcPort = 0 ;
82
- apiServerOptions . apiTlsEnabled = false ;
83
- apiServerOptions . plugins = [
84
- {
85
- packageName : "@hyperledger/cactus-plugin-keychain-vault" ,
86
- type : PluginImportType . Remote ,
87
- action : PluginImportAction . Install ,
88
- options : {
89
- keychainId : "_keychainId_" ,
90
- instanceId : "_instanceId_" ,
91
- remoteConfig : configuration ,
42
+ beforeAll ( async ( ) => {
43
+ await vaultTestContainer . start ( ) ;
44
+ const pluginsPath = path . join (
45
+ __dirname , // start at the current file's path
46
+ "../../../../../../" , // walk back up to the project root
47
+ ".tmp/test/cmd-api-server/remote-plugin-imports_test" , // the dir path from the root
48
+ uuidv4 ( ) , // then a random directory to ensure proper isolation
49
+ ) ;
50
+ const pluginManagerOptionsJson = JSON . stringify ( { pluginsPath } ) ;
51
+
52
+ const ci = await Containers . getById ( vaultTestContainer . containerId ) ;
53
+ const vaultIpAddr = await Containers . getContainerInternalIp ( ci ) ;
54
+ const configService = new ConfigService ( ) ;
55
+ const apiServerOptions = await configService . newExampleConfig ( ) ;
56
+ apiServerOptions . authorizationProtocol = AuthorizationProtocol . NONE ;
57
+ apiServerOptions . pluginManagerOptionsJson = pluginManagerOptionsJson ;
58
+ apiServerOptions . configFile = "" ;
59
+ apiServerOptions . apiCorsDomainCsv = "*" ;
60
+ apiServerOptions . apiPort = 0 ;
61
+ apiServerOptions . cockpitPort = 0 ;
62
+ apiServerOptions . grpcPort = 0 ;
63
+ apiServerOptions . apiTlsEnabled = false ;
64
+
65
+ const config = await configService . newExampleConfigConvict (
66
+ apiServerOptions ,
67
+ ) ;
68
+
69
+ apiServer = new ApiServer ( {
70
+ config : config . getProperties ( ) ,
71
+ } ) ;
72
+
73
+ // const hostPortVault = await vaultTestContainer.getHostPortHttp();
74
+ const vaultHost = `http://${ vaultIpAddr } :${ K_DEFAULT_VAULT_HTTP_PORT } ` ;
75
+
76
+ pluginContainer = new CactusKeychainVaultServer ( {
77
+ envVars : [
78
+ `VAULT_HOST=${ vaultHost } ` ,
79
+ `VAULT_TOKEN=${ K_DEFAULT_VAULT_DEV_ROOT_TOKEN } ` ,
80
+ "HOST=0.0.0.0:8080" ,
81
+ ] ,
82
+ } ) ;
83
+ await pluginContainer . start ( ) ;
84
+ const hostPort = await pluginContainer . getHostPortHttp ( ) ;
85
+
86
+ const configuration = new Configuration ( {
87
+ basePath : `http://localhost:${ hostPort } ` ,
88
+ } ) ;
89
+ apiClient = new DefaultApi ( configuration ) ;
90
+
91
+ apiServerOptions . plugins = [
92
+ {
93
+ packageName : "@hyperledger/cactus-plugin-keychain-vault" ,
94
+ type : PluginImportType . Remote ,
95
+ action : PluginImportAction . Install ,
96
+ options : {
97
+ keychainId : "_keychainId_" ,
98
+ instanceId : "_instanceId_" ,
99
+ remoteConfig : configuration ,
100
+ } ,
92
101
} ,
93
- } ,
94
- ] ;
95
- const config = await configService . newExampleConfigConvict ( apiServerOptions ) ;
102
+ ] ;
96
103
97
- const apiServer = new ApiServer ( {
98
- config : config . getProperties ( ) ,
104
+ await expect ( apiServer . start ( ) ) . not . toReject ;
99
105
} ) ;
106
+ test ( testCase , async ( ) => {
107
+ const key = uuidv4 ( ) ;
108
+ const expected = uuidv4 ( ) ;
100
109
101
- await t . doesNotReject ( apiServer . start ( ) , "Started API server OK" ) ;
102
- test . onFinish ( ( ) => apiServer . shutdown ( ) ) ;
110
+ await apiClient . setKeychainEntryV1 ( { key, value : expected } ) ;
111
+ const {
112
+ data : { value : actual } ,
113
+ } = await apiClient . getKeychainEntryV1 ( { key } ) ;
103
114
104
- const key = uuidv4 ( ) ;
105
- const expected = uuidv4 ( ) ;
106
-
107
- await apiClient . setKeychainEntryV1 ( { key, value : expected } ) ;
108
- const {
109
- data : { value : actual } ,
110
- } = await apiClient . getKeychainEntryV1 ( { key } ) ;
111
-
112
- t . equal ( actual , expected , "Keychain stored value matches input OK" ) ;
113
-
114
- t . end ( ) ;
115
+ expect ( actual ) . toEqual ( expected ) ;
116
+ } ) ;
115
117
} ) ;
0 commit comments