diff --git a/test/config.js b/test/config.js index 99b4736..af5f660 100644 --- a/test/config.js +++ b/test/config.js @@ -1,5 +1,7 @@ const path = require('path') -const { Config } = require('@holochain/tryorama') +const { + Config +} = require('@holochain/tryorama') const dnaName = "DeepKey" const dnaId = "dpki_happ" @@ -14,36 +16,39 @@ const networkType = process.env.APP_SPEC_NETWORK_TYPE || "sim2h" let network = {} // override the transport_config if we are in the Final Exam context! if (process.env.HC_TRANSPORT_CONFIG) { - network=require(process.env.HC_TRANSPORT_CONFIG) + network = require(process.env.HC_TRANSPORT_CONFIG) } else { - network = - ( networkType === 'websocket' - ? Config.network('websocket') + network = + (networkType === 'websocket' ? + Config.network('websocket') - : networkType === 'memory' - ? Config.network('memory') + : + networkType === 'memory' ? + Config.network('memory') - : networkType === 'sim1h' - ? { - type: 'sim1h', - dynamo_url: 'http://localhost:8000' - } + : + networkType === 'sim1h' ? { + type: 'sim1h', + dynamo_url: 'http://localhost:8000' + } - : networkType === 'sim2h' - ? { - type: 'sim2h', - sim2h_url: 'ws://localhost:9000' - } + : + networkType === 'sim2h' ? { + type: 'sim2h', + sim2h_url: 'ws://localhost:9000' + } - : (() => {throw new Error(`Unsupported network type: ${networkType}`)})() - ) + : + (() => { + throw new Error(`Unsupported network type: ${networkType}`) + })() + ) } const logger = { type: 'debug', rules: { - rules: [ - { + rules: [{ exclude: true, pattern: '.*parity.*' }, @@ -91,11 +96,16 @@ const logger = { const commonConfig = { logger, network, - passphrase_service: {type:'mock',passphrase:""} + passphrase_service: { + type: 'mock', + passphrase: "" + } } -const simple_conductor_config = (agent) => Config.gen(({uuid}) => [{ +const simple_conductor_config = (agent) => Config.gen(({ + uuid + }) => [{ id: 'dpki_happ', agent: { id: `${agent}`, @@ -109,14 +119,16 @@ const simple_conductor_config = (agent) => Config.gen(({uuid}) => [{ uuid, } }], - commonConfig - // dpki: { - // instance_id: 'dpki_happ', - // init_params: {"revocation_key": "HcSCiPdMkst9geux7y7kPoVx3W54Ebwkk6fFWjH9V6oIbqi77H4i9qGXRsDcdbi","signed_auth_key":"zJkRXrrbvbzbH96SpapO5lDWoElpzB1rDE+4zbo/VthM/mp9qNKaVsGiVKnHkqT4f5J4MGN+q18xP/hwQUKyDA=="} - // } - ) + commonConfig + // dpki: { + // instance_id: 'dpki_happ', + // init_params: {"revocation_key": "HcSCiPdMkst9geux7y7kPoVx3W54Ebwkk6fFWjH9V6oIbqi77H4i9qGXRsDcdbi","signed_auth_key":"zJkRXrrbvbzbH96SpapO5lDWoElpzB1rDE+4zbo/VthM/mp9qNKaVsGiVKnHkqT4f5J4MGN+q18xP/hwQUKyDA=="} + // } +) -const simple_2_conductor_config = (agent) => Config.gen(({uuid}) => [{ +const simple_2_conductor_config = (agent) => Config.gen(({ + uuid + }) => [{ id: 'dpki_happ', agent: { id: `${agent}`, @@ -130,11 +142,14 @@ const simple_2_conductor_config = (agent) => Config.gen(({uuid}) => [{ uuid, } }], - commonConfig, - // dpki: { - // instance_id: 'dpki_happ', - // init_params: {"revocation_key": "HcSCI7fRqt5wb7r6i46f5AeGW6zcNuq3i94fQVtFOPromhzoukr9DabcZqzxzir","signed_auth_key":"bQNCtt9Xa7Ii4mCgOGSt8InVLA6HbrFjhYBoc4lDKMtxbY65kQoMNR/mHCuBq5rBYtyaZXG9Jpa9o8WD2eSrCw=="} - // } - ) + commonConfig, + // dpki: { + // instance_id: 'dpki_happ', + // init_params: {"revocation_key": "HcSCI7fRqt5wb7r6i46f5AeGW6zcNuq3i94fQVtFOPromhzoukr9DabcZqzxzir","signed_auth_key":"bQNCtt9Xa7Ii4mCgOGSt8InVLA6HbrFjhYBoc4lDKMtxbY65kQoMNR/mHCuBq5rBYtyaZXG9Jpa9o8WD2eSrCw=="} + // } +) -module.exports = { simple_conductor_config, simple_2_conductor_config } +module.exports = { + simple_conductor_config, + simple_2_conductor_config +} \ No newline at end of file diff --git a/test/index.js b/test/index.js index ca6163c..447a584 100644 --- a/test/index.js +++ b/test/index.js @@ -1,4 +1,10 @@ -const { Orchestrator, tapeExecutor, combine, callSync, localOnly } = require('@holochain/tryorama') +const { + Orchestrator, + tapeExecutor, + combine, + callSync, + localOnly +} = require('@holochain/tryorama') const MIN_EXPECTED_SCENARIOS = 1 @@ -30,17 +36,16 @@ require('./unit_test/manual_dpki/update_auth_entries')(orchestrator.registerScen require('./unit_test/manual_dpki/set_up_conductor')(orchestrator.registerScenario) require('./unit_test/manual_dpki/revoke_rev_key')(orchestrator.registerScenario) require('./unit_test/manual_dpki/test_init')(orchestrator.registerScenario) -require('./unit_test/manual_dpki/notification')(orchestrator.registerScenario) +require('./unit_test/manual_dpki/manual_device_handshake')(orchestrator.registerScenario) const num = orchestrator.numRegistered() if (num < MIN_EXPECTED_SCENARIOS) { console.error(`Expected at least ${MIN_EXPECTED_SCENARIOS} scenarios, but only ${num} were registered!`) process.exit(1) -} -else { +} else { console.log(`Registered ${num} scenarios (at least ${MIN_EXPECTED_SCENARIOS} were expected)`) } orchestrator.run().then(stats => { console.log("All done.") -}) +}) \ No newline at end of file diff --git a/test/manual.js b/test/manual.js index d2dc18d..8d4bad2 100644 --- a/test/manual.js +++ b/test/manual.js @@ -1,5 +1,8 @@ const test = require('tape'); -const { Conductor, DnaInstance } = require("@holochain/holochain-nodejs") +const { + Conductor, + DnaInstance +} = require("@holochain/holochain-nodejs") const toml = ` @@ -42,18 +45,18 @@ init_params = "{}" test('Initial test (run)', t => { - Conductor.run(toml, (stop, conductor) => { + Conductor.run(toml, (stop, conductor) => { - const instance = new DnaInstance('deepkey_instance', conductor) - const keyset_root_address = instance.call("dpki", "init_dpki", {}) - // console.log("keyset_root->",keyset_root_address); - t.ok(keyset_root_address.Ok) + const instance = new DnaInstance('deepkey_instance', conductor) + const keyset_root_address = instance.call("dpki", "init_dpki", {}) + // console.log("keyset_root->",keyset_root_address); + t.ok(keyset_root_address.Ok) - const get_root_address = instance.call("dpki", "get_initialization_data", {}) - // console.log("->",get_root_address); - t.ok(get_root_address.Ok) + const get_root_address = instance.call("dpki", "get_initialization_data", {}) + // console.log("->",get_root_address); + t.ok(get_root_address.Ok) - stop() - t.end() - }) -}) + stop() + t.end() + }) +}) \ No newline at end of file diff --git a/test/unit_test/auto_dpki/test_init.js b/test/unit_test/auto_dpki/test_init.js index d32cbb0..ba4e106 100644 --- a/test/unit_test/auto_dpki/test_init.js +++ b/test/unit_test/auto_dpki/test_init.js @@ -20,4 +20,4 @@ // await liza.kill() // await jack.kill() // }) -// } +// } \ No newline at end of file diff --git a/test/unit_test/manual_dpki/manual_device_handshake.js b/test/unit_test/manual_dpki/manual_device_handshake.js new file mode 100644 index 0000000..ca33dfb --- /dev/null +++ b/test/unit_test/manual_dpki/manual_device_handshake.js @@ -0,0 +1,54 @@ +const { + simple_conductor_config, + simple_2_conductor_config +} = require('../../config') + +async function liza_conductor_init(agent) { + return await agent.callSync('dpki_happ', "dpki", "init_dpki", { + params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}" + }) +} + +async function jack_conductor_init(agent) { + return await agent.callSync("dpki_happ", "dpki", "init_dpki", { + params: "{\"signed_auth_key\":\"sCkN1Yqaxeso1JicovXBruDXtx20Sofa+I6A6xpe3LjJQ6zvqwrJ3qbbDgLmFIPqF5RAKWTSMI7BZr6+06k/DA==\"}" + }) +} + +// THis Scenario was wirten to demonstrate manually trying to handshake +// note for Jacks conductor the `init_dpki` only passes signed_auth_key and no FDA +// In this situation you would have to make a manual handshake as demonstrated bellow +module.exports = (scenario) => { + scenario("testing the notification to device handshaking", async (s, t) => { + const { + liza, + jack + } = await s.players({ + liza: simple_conductor_config("liza"), + jack: simple_2_conductor_config("jack") + }, true) + + await s.consistency() + + let a = await liza_conductor_init(liza) + t.ok(a.Ok) + a = await jack_conductor_init(jack) + t.ok(a.Err) + t.equal(a.Err.Internal, "DeepKey Error: init() was successfull but you have to still handshake with your FirstDeepKeyAgent") + const jack_receives = await jack.callSync("dpki_happ", "dpki", "send_handshake_notify", { + to: liza.info('dpki_happ').agentAddress + }) + console.log("jack_receives:: ", jack_receives); + t.ok(jack_receives.Ok) + + const is_authorized = await liza.callSync("dpki_happ", "dpki", "authorize_device", { + new_agent_hash: jack.info('dpki_happ').agentAddress, + new_agent_signed_xor: jack_receives.Ok + }) + console.log("is_authorized:: ", is_authorized); + t.deepEqual(is_authorized.Ok, null) + + await liza.kill() + await jack.kill() + }) +} \ No newline at end of file diff --git a/test/unit_test/manual_dpki/notification.js b/test/unit_test/manual_dpki/notification.js deleted file mode 100644 index 44b06c9..0000000 --- a/test/unit_test/manual_dpki/notification.js +++ /dev/null @@ -1,33 +0,0 @@ -const { simple_conductor_config, simple_2_conductor_config } = require('../../config') - -async function liza_conductor_init (agent){ - return await agent.callSync('dpki_happ', "dpki", "init_dpki", {params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}"}) -} - -async function jack_conductor_init (agent){ - return await agent.callSync("dpki_happ", "dpki", "init_dpki", {params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"sCkN1Yqaxeso1JicovXBruDXtx20Sofa+I6A6xpe3LjJQ6zvqwrJ3qbbDgLmFIPqF5RAKWTSMI7BZr6+06k/DA==\"}"}) -} - -module.exports = (scenario) => { - scenario("testing the notification to device handshaking", async (s, t) => { - const { liza, jack } = await s.players({ liza: simple_conductor_config("liza"), jack: simple_2_conductor_config("jack")}, true) - - await s.consistency() - - let a = await liza_conductor_init(liza) - t.ok(a.Ok) - a= await jack_conductor_init(jack) - t.ok(a.Ok) - - const jack_receives = await jack.callSync("dpki_happ", "dpki", "send_handshake_notify", {to:liza.info('dpki_happ').agentAddress}) - console.log("jack_receives:: ",jack_receives); - t.ok(jack_receives.Ok) - - const is_authorized = await liza.callSync("dpki_happ", "dpki", "authorize_device", {new_agent_hash: jack.info('dpki_happ').agentAddress, new_agent_signed_xor: jack_receives.Ok }) - console.log("is_authorized:: ",is_authorized); - t.deepEqual(is_authorized.Ok,null) - - await liza.kill() - await jack.kill() - }) -} diff --git a/test/unit_test/manual_dpki/revoke_rev_key.js b/test/unit_test/manual_dpki/revoke_rev_key.js index e2be9c0..50597be 100644 --- a/test/unit_test/manual_dpki/revoke_rev_key.js +++ b/test/unit_test/manual_dpki/revoke_rev_key.js @@ -1,40 +1,55 @@ -const { simple_conductor_config } = require('../../config') +const { + simple_conductor_config +} = require('../../config') const REVOCATION_KEY = "HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi"; const NEW_REVOCATION_KEY = "HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi"; const REV_SIGNED_BY_REV_KEY = "xLD9u9XLBqr295xacnsaS9MTRmDAAzIpzvIOrR+2wvDOWezD6aFyEGsUoml/MKKga1i718uVmwL//Rze300CAA=="; const BAD_SIGNED_REV_KEY = "Jkz3AWHO5bEZ11OpsNeotTIr3CGH3wZcyqUAae+xEVy+MwXhrAS1lfzUbWSRQgsSMWUNSjYTtE9NNUHXPkQkBg==" -async function conductor_init (liza){ - return await liza.callSync('dpki_happ', "dpki", "init_dpki", {params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}"}) +async function conductor_init(liza) { + return await liza.callSync('dpki_happ', "dpki", "init_dpki", { + params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}" + }) } module.exports = (scenario) => { - scenario("testing the initial set up process and trying to update it", async(s, t) => { - const { liza } = await s.players({ liza: simple_conductor_config('liza')}, true) + scenario("testing the initial set up process and trying to update it", async (s, t) => { + const { + liza + } = await s.players({ + liza: simple_conductor_config('liza') + }, true) await s.consistency() await conductor_init(liza) -// Check if your getting the right hash + // Check if your getting the right hash const my_rules = await liza.call('dpki_happ', "dpki", "get_rules", {}) - console.log("My Rules: ",my_rules.Ok[0]); - t.ok(my_rules.Ok[0].entry.revocationKey,REVOCATION_KEY) - -// The signature should not match and throw an error - const err_on_commit = await liza.callSync('dpki_happ', "dpki", "update_rules", {revocation_key:NEW_REVOCATION_KEY, signed_old_revocation_key:BAD_SIGNED_REV_KEY}) + console.log("My Rules: ", my_rules.Ok[0]); + t.ok(my_rules.Ok[0].entry.revocationKey, REVOCATION_KEY) + + // The signature should not match and throw an error + const err_on_commit = await liza.callSync('dpki_happ', "dpki", "update_rules", { + revocation_key: NEW_REVOCATION_KEY, + signed_old_revocation_key: BAD_SIGNED_REV_KEY + }) console.log(err_on_commit); - t.ok(err_on_commit.Err ) + t.ok(err_on_commit.Err) - const sucessfull_commit = await liza.callSync('dpki_happ', "dpki", "update_rules", {revocation_key:NEW_REVOCATION_KEY, signed_old_revocation_key:REV_SIGNED_BY_REV_KEY}) - t.ok(sucessfull_commit.Ok ) + const sucessfull_commit = await liza.callSync('dpki_happ', "dpki", "update_rules", { + revocation_key: NEW_REVOCATION_KEY, + signed_old_revocation_key: REV_SIGNED_BY_REV_KEY + }) + t.ok(sucessfull_commit.Ok) -// Check if your getting the right hash + + // Check if your getting the right hash const my_updated_rules = await liza.call('dpki_happ', "dpki", "get_rules", {}) - console.log("My Updated Rules: ",my_updated_rules.Ok[0]); - t.deepEqual(my_updated_rules.Ok[0].entry.revocationKey,NEW_REVOCATION_KEY ) + console.log("My Updated Rules: ", my_updated_rules.Ok[0]); + t.deepEqual(my_updated_rules.Ok[0].entry.revocationKey, NEW_REVOCATION_KEY) await liza.kill() }) -} +} \ No newline at end of file diff --git a/test/unit_test/manual_dpki/set_up_conductor.js b/test/unit_test/manual_dpki/set_up_conductor.js index 13cda36..7c34df7 100644 --- a/test/unit_test/manual_dpki/set_up_conductor.js +++ b/test/unit_test/manual_dpki/set_up_conductor.js @@ -1,60 +1,74 @@ -const { simple_conductor_config } = require('../../config') +const { + simple_conductor_config +} = require('../../config') const REVOCATION_KEY = "HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi"; -const SIGNED_AUTH_KEY_1 ="CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ=="; +const SIGNED_AUTH_KEY_1 = "CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ=="; const WRONG_SINGED_AUTH_KEY = "D16Dl3Cywos/AS/ANPqsvkRZCCKWPd1KTkdANOxqG1MXRtdCaTYYAOO13mcYYtfzWbaagwLk5oFlns2uQneUDg=="; -const SIGNED_AUTH_KEY_2 ="LbEReAxFLkkzfOHRBixC7+DYKGao6lPBYsUycVg3NHmNx7p8237/9unBwrt/o+9P4IWkKR+QCYeFxqBNRnn+Dg=="; +const SIGNED_AUTH_KEY_2 = "LbEReAxFLkkzfOHRBixC7+DYKGao6lPBYsUycVg3NHmNx7p8237/9unBwrt/o+9P4IWkKR+QCYeFxqBNRnn+Dg=="; const AGENT_SIG_KEY_1 = "HcSCj3HIbzRbnkg6hcgqcoHAMKdgxsjrivPc649dodOU4d6jGw8uW83Xu9mkiva"; -const SIGNED_AGENT_SIG_KEY_1_BY_REV_KEY ="JQKlrv9civTtfD20b8jCpSFgoaowZL7qASjYJpY7LOtYIbT7a5XWLte8jjvX0p54mRdCcNWGW47vUl8q3k1+Dw=="; +const SIGNED_AGENT_SIG_KEY_1_BY_REV_KEY = "JQKlrv9civTtfD20b8jCpSFgoaowZL7qASjYJpY7LOtYIbT7a5XWLte8jjvX0p54mRdCcNWGW47vUl8q3k1+Dw=="; const AGENT_ENC_KEY_1 = "HcKciaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; const SIGNED_AGENT_ENC_KEY_1_BY_REV_KEY = "LSUEatYDtH5RLEPq87NfF79p9GXEUKUgLLybJMMxS3CquQp/tUvWhEVdAWBkfgEkCKF8tomG+SO6mnb/E32vAw=="; const AGENT_SIG_KEY_2 = "HcScjarBF95Xec3kis7bduuhP7hevykn8iqFGNqCxhs6ykaqFcZKhQ4f3F3535a"; -async function conductor_init (liza){ - return await liza.callSync('dpki_happ', "dpki", "init_dpki", {params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}"}) +async function conductor_init(liza) { + return await liza.callSync('dpki_happ', "dpki", "init_dpki", { + params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}" + }) } module.exports = (scenario) => { - scenario("testing out how conductor should be set up", async(s, t) => { + scenario("testing out how conductor should be set up", async (s, t) => { - const { liza } = await s.players({ liza: simple_conductor_config('liza')}, true) + const { + liza + } = await s.players({ + liza: simple_conductor_config('liza') + }, true) await s.consistency() -// On conductor_init we have to make this call + // On conductor_init we have to make this call let address = await conductor_init(liza) t.ok(address.Ok) -// This is to just test out if we get the right keyset_root address + // This is to just test out if we get the right keyset_root address const keyset_root_address = await liza.call('dpki_happ', "dpki", "get_initialization_data", {}) // add this test when the init is fixed // t.equal(keyset_root_address.Ok,address.Ok) t.ok(keyset_root_address.Ok) -// Check if the key exist for the key -// This is befor this is created - const checking_key_1 = await liza.call('dpki_happ', "dpki", "key_status", {key:AGENT_SIG_KEY_1}) - t.deepEqual(checking_key_1.Ok,"Doesn't Exists" ) + // Check if the key exist for the key + // This is befor this is created + const checking_key_1 = await liza.call('dpki_happ', "dpki", "key_status", { + key: AGENT_SIG_KEY_1 + }) + t.deepEqual(checking_key_1.Ok, "Doesn't Exists") -// Lets create an agent key + // Lets create an agent key const key_commit = await liza.callSync('dpki_happ', "dpki", "create_agent_key", { - agent_name:"MY_AGENT" + agent_name: "MY_AGENT" }) - t.deepEqual(key_commit.Ok,null) + t.deepEqual(key_commit.Ok, null) let all_keys = await liza.call('dpki_happ', "dpki", "get_all_keys", {}) t.deepEqual(all_keys.Ok.length, 2) -// Let register an apps -// In practical use this call will be called from a hApp DNA during genesis to register itself + // Let register an apps + // In practical use this call will be called from a hApp DNA during genesis to register itself let apps = await liza.call('dpki_happ', "dpki", "get_registered_key", {}) console.log("Apps: ", apps); t.deepEqual(apps.Ok.length, 0) - let registered_key = await liza.call('dpki_happ', "dpki", "register_key", {app_dna_hash: "Qem...", app_name: "App Name...", public_key: all_keys.Ok[0].newKey}) + let registered_key = await liza.call('dpki_happ', "dpki", "register_key", { + app_dna_hash: "Qem...", + app_name: "App Name...", + public_key: all_keys.Ok[0].newKey + }) t.ok(registered_key.Ok) @@ -62,7 +76,11 @@ module.exports = (scenario) => { console.log("Apps: ", apps); t.deepEqual(apps.Ok.length, 1) - registered_key = await liza.call('dpki_happ', "dpki", "register_key", {app_dna_hash: "Qww...", app_name: "App2 Name...", public_key: all_keys.Ok[0].newKey}) + registered_key = await liza.call('dpki_happ', "dpki", "register_key", { + app_dna_hash: "Qww...", + app_name: "App2 Name...", + public_key: all_keys.Ok[0].newKey + }) t.ok(registered_key.Ok) @@ -70,47 +88,57 @@ module.exports = (scenario) => { console.log("Apps: ", apps); t.deepEqual(apps.Ok.length, 2) -/* -Check if the keys exist for the key - Now it should exist -*/ + /* + Check if the keys exist for the key + Now it should exist + */ - // Checking Agents initial Signing key - const checking_key_2 = await liza.call('dpki_happ', "dpki", "key_status", {key:AGENT_SIG_KEY_1}) - t.deepEqual(checking_key_2.Ok,"live" ) + // Checking Agents initial Signing key + const checking_key_2 = await liza.call('dpki_happ', "dpki", "key_status", { + key: AGENT_SIG_KEY_1 + }) + t.deepEqual(checking_key_2.Ok, "live") - // Ceecking Agents initial Encryption key - const checking_key_3 = await liza.call('dpki_happ', "dpki", "key_status", {key:AGENT_ENC_KEY_1}) - t.deepEqual(checking_key_3.Ok,"live" ) + // Ceecking Agents initial Encryption key + const checking_key_3 = await liza.call('dpki_happ', "dpki", "key_status", { + key: AGENT_ENC_KEY_1 + }) + t.deepEqual(checking_key_3.Ok, "live") -// Lets Update the keys just created + // Lets Update the keys just created const updated_key = await liza.callSync('dpki_happ', "dpki", "update_key", { - old_key:AGENT_SIG_KEY_1, - signed_old_key:SIGNED_AGENT_SIG_KEY_1_BY_REV_KEY, - context:"NEWAGENT" + old_key: AGENT_SIG_KEY_1, + signed_old_key: SIGNED_AGENT_SIG_KEY_1_BY_REV_KEY, + context: "NEWAGENT" }) - console.log("Updated Key: ",updated_key); - t.deepEqual(updated_key.Ok,null) + console.log("Updated Key: ", updated_key); + t.deepEqual(updated_key.Ok, null) -// Check if the key exist for the key -// Now the old key should be shown as updated and the new should be live - const checking_key_4 = await liza.call('dpki_happ', "dpki", "key_status", {key:AGENT_SIG_KEY_1}) - t.deepEqual(checking_key_4.Ok,"modified" ) + // Check if the key exist for the key + // Now the old key should be shown as updated and the new should be live + const checking_key_4 = await liza.call('dpki_happ', "dpki", "key_status", { + key: AGENT_SIG_KEY_1 + }) + t.deepEqual(checking_key_4.Ok, "modified") - const checking_key_5 = await liza.call('dpki_happ', "dpki", "key_status", {key:AGENT_SIG_KEY_2}) - t.deepEqual(checking_key_5.Ok,"live" ) + const checking_key_5 = await liza.call('dpki_happ', "dpki", "key_status", { + key: AGENT_SIG_KEY_2 + }) + t.deepEqual(checking_key_5.Ok, "live") const deleated_key = await liza.callSync('dpki_happ', "dpki", "delete_key", { - old_key:AGENT_ENC_KEY_1, - signed_old_key:SIGNED_AGENT_ENC_KEY_1_BY_REV_KEY + old_key: AGENT_ENC_KEY_1, + signed_old_key: SIGNED_AGENT_ENC_KEY_1_BY_REV_KEY }) console.log("deleated_key: ", deleated_key); - t.equal(deleated_key.Ok,null) + t.equal(deleated_key.Ok, null) console.log(" Deleated Key Succesfully "); - const checking_key_6 = await liza.call('dpki_happ', "dpki", "key_status", {key:AGENT_ENC_KEY_1}) - t.deepEqual(checking_key_6.Ok,"deleted" ) + const checking_key_6 = await liza.call('dpki_happ', "dpki", "key_status", { + key: AGENT_ENC_KEY_1 + }) + t.deepEqual(checking_key_6.Ok, "deleted") await liza.kill() }) -} +} \ No newline at end of file diff --git a/test/unit_test/manual_dpki/test_init.js b/test/unit_test/manual_dpki/test_init.js index 06823e6..c60edad 100644 --- a/test/unit_test/manual_dpki/test_init.js +++ b/test/unit_test/manual_dpki/test_init.js @@ -1,15 +1,21 @@ -const { simple_conductor_config } = require('../../config') +const { + simple_conductor_config +} = require('../../config') module.exports = (scenario) => { - scenario("testing the init process", async(s, t) => { - const { liza } = await s.players({ + scenario("testing the init process", async (s, t) => { + const { + liza + } = await s.players({ liza: simple_conductor_config('liza'), }, true) await s.consistency() - let c1 = await liza.callSync('dpki_happ', "dpki", "init_dpki", {params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}"}) - console.log("INIT:: ",c1); + let c1 = await liza.callSync('dpki_happ', "dpki", "init_dpki", { + params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}" + }) + console.log("INIT:: ", c1); t.ok(c1.Ok) let get_init_data = await liza.call('dpki_happ', "dpki", "get_initialization_data", {}) @@ -28,4 +34,4 @@ module.exports = (scenario) => { await liza.kill() }) -} +} \ No newline at end of file diff --git a/test/unit_test/manual_dpki/update_auth_entries.js b/test/unit_test/manual_dpki/update_auth_entries.js index c300a04..08377bf 100644 --- a/test/unit_test/manual_dpki/update_auth_entries.js +++ b/test/unit_test/manual_dpki/update_auth_entries.js @@ -1,17 +1,25 @@ -const { simple_conductor_config } = require('../../config') +const { + simple_conductor_config +} = require('../../config') const REVOCATION_KEY = "HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi"; // const SIGNED_AUTH_KEY_1 ="zJkRXrrbvbzbH96SpapO5lDWoElpzB1rDE+4zbo/VthM/mp9qNKaVsGiVKnHkqT4f5J4MGN+q18xP/hwQUKyDA=="; // const WRONG_SINGED_AUTH_KEY = "D16Dl3Cywos/AS/ANPqsvkRZCCKWPd1KTkdANOxqG1MXRtdCaTYYAOO13mcYYtfzWbaagwLk5oFlns2uQneUDg=="; // const SIGNED_AUTH_KEY_2 ="MG2L0DObZ+m/Zr4bWp/LRUD5FM5W/QZtYafxVEhehyujpPvGdgROCAApAIXl+UpQy1evDU+LnShZzY/emIbKDw=="; -async function conductor_init (liza){ - return await liza.callSync('dpki_happ', "dpki", "init_dpki", {params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}"}) +async function conductor_init(liza) { + return await liza.callSync('dpki_happ', "dpki", "init_dpki", { + params: "{\"revocation_key\": \"HcSCIgvyd46Q4d9xa4gesx8j5tE7crna8m9U4Z63yzmf5aob6t3mKTNIp8mp8fi\",\"signed_auth_key\":\"CPhaw45L6MjxPOsVBFsTYkl35hS4h9yRNqsl1fqfNx5P6z6l6WE6aLSrBjD3Dfe3HSg3vNSHtC1QeN0FWBo+DQ==\"}" + }) } module.exports = (scenario) => { - scenario("testing checks if entries have been pushed", async(s, t) => { - const { liza } = await s.players({ liza: simple_conductor_config('liza')}, true) + scenario("testing checks if entries have been pushed", async (s, t) => { + const { + liza + } = await s.players({ + liza: simple_conductor_config('liza') + }, true) await s.consistency() // On conductor_init we have to make this call @@ -22,78 +30,94 @@ module.exports = (scenario) => { await liza.kill() }) - scenario("testing to check if the DNA is initialized", async(s, t) => { - const { liza } = await s.players({ liza: simple_conductor_config('liza')}, true) + scenario("testing to check if the DNA is initialized", async (s, t) => { + const { + liza + } = await s.players({ + liza: simple_conductor_config('liza') + }, true) await s.consistency() let check = await liza.call('dpki_happ', "dpki", "is_initialized", {}) - console.log("IS INITIALIZED: ",check); + console.log("IS INITIALIZED: ", check); t.notOk(check.Ok) let address = await conductor_init(liza) check = await liza.call('dpki_happ', "dpki", "is_initialized", {}) - console.log("IS INITIALIZED: ",check); + console.log("IS INITIALIZED: ", check); t.ok(check.Ok) await liza.kill() }) - scenario("testing if create rules before the keyset_root should throw an error", async(s, t) => { - const { liza } = await s.players({ liza: simple_conductor_config('liza')}, true) + scenario("testing if create rules before the keyset_root should throw an error", async (s, t) => { + const { + liza + } = await s.players({ + liza: simple_conductor_config('liza') + }, true) await s.consistency() - // This is to just test out if we get the right keyset_root address + // This is to just test out if we get the right keyset_root address const keyset_root_address = await liza.call('dpki_happ', "dpki", "get_initialization_data", {}) - console.log("My KeysetRoot Address: ",keyset_root_address); - t.deepEqual(keyset_root_address.Err.Internal, 'fn handle_get_my_keyset_root(): No KeysetRoot Exists' ) + console.log("My KeysetRoot Address: ", keyset_root_address); + t.deepEqual(keyset_root_address.Err.Internal, 'fn handle_get_my_keyset_root(): No KeysetRoot Exists') await liza.kill() }) - scenario("testing the initial set up process and trying to update it", async(s, t) => { - const { liza } = await s.players({ liza: simple_conductor_config('liza')}, true) + scenario("testing the initial set up process and trying to update it", async (s, t) => { + const { + liza + } = await s.players({ + liza: simple_conductor_config('liza') + }, true) await s.consistency() await conductor_init(liza) const check_rules = await liza.call('dpki_happ', "dpki", "get_rules", {}) - console.log("Initial Rules: ",check_rules); - t.deepEqual(check_rules.Ok.length,1 ) + console.log("Initial Rules: ", check_rules); + t.deepEqual(check_rules.Ok.length, 1) -// Check if your getting the right hash + // Check if your getting the right hash const my_rules = await liza.call('dpki_happ', "dpki", "get_rules", {}) - console.log("My Rules: ",my_rules.Ok[0]); - t.deepEqual(my_rules.Ok[0].entry.revocationKey,REVOCATION_KEY) + console.log("My Rules: ", my_rules.Ok[0]); + t.deepEqual(my_rules.Ok[0].entry.revocationKey, REVOCATION_KEY) -// Lets create an authorizor key + // Lets create an authorizor key const authorizor_commit = await liza.call('dpki_happ', "dpki", "get_authorizor", {}) t.ok(authorizor_commit.Ok) -// Check if the key exist for the authorizor - const not_registered_key = await liza.call('dpki_happ', "dpki", "key_status", {key:"Not-Registered-Key"}) - t.deepEqual(not_registered_key.Ok,"Doesn\'t Exists" ) - -// Check if the key exist for the authorizor - const checking_authorizor_key = await liza.call('dpki_happ', "dpki", "key_status", {key:authorizor_commit.Ok.authorizationKey}) - t.deepEqual(checking_authorizor_key.Ok,"live" ) - -// TODO: Waiting for the Auth key gen process in CLI and HDK create the same keys -// // Lets create an authorizor key -// const updated_authorizor_commit = await liza.callSync('dpki_happ', "dpki", "set_authorizor", { -// authorization_key_path: 2, -// signed_auth_key:SIGNED_AUTH_KEY_2 -// }) -// t.ok(updated_authorizor_commit.Ok) -// -// const checking_new_authorizor_key = await liza.callSync('dpki_happ', "dpki", "key_status", {key:updated_authorizor_commit.Ok}) -// t.deepEqual(checking_new_authorizor_key.Ok,"live" ) -// -// // Check if the key exist for the authorizor -// const checking_old_authorizor_key = await liza.callSync('dpki_happ', "dpki", "key_status", {key:authorizor_commit.Ok}) -// t.deepEqual(checking_old_authorizor_key.Ok,"modified" ) + // Check if the key exist for the authorizor + const not_registered_key = await liza.call('dpki_happ', "dpki", "key_status", { + key: "Not-Registered-Key" + }) + t.deepEqual(not_registered_key.Ok, "Doesn\'t Exists") + + // Check if the key exist for the authorizor + const checking_authorizor_key = await liza.call('dpki_happ', "dpki", "key_status", { + key: authorizor_commit.Ok.authorizationKey + }) + t.deepEqual(checking_authorizor_key.Ok, "live") + + // TODO: Waiting for the Auth key gen process in CLI and HDK create the same keys + // // Lets create an authorizor key + // const updated_authorizor_commit = await liza.callSync('dpki_happ', "dpki", "set_authorizor", { + // authorization_key_path: 2, + // signed_auth_key:SIGNED_AUTH_KEY_2 + // }) + // t.ok(updated_authorizor_commit.Ok) + // + // const checking_new_authorizor_key = await liza.callSync('dpki_happ', "dpki", "key_status", {key:updated_authorizor_commit.Ok}) + // t.deepEqual(checking_new_authorizor_key.Ok,"live" ) + // + // // Check if the key exist for the authorizor + // const checking_old_authorizor_key = await liza.callSync('dpki_happ', "dpki", "key_status", {key:authorizor_commit.Ok}) + // t.deepEqual(checking_old_authorizor_key.Ok,"modified" ) await liza.kill() }) -} +} \ No newline at end of file diff --git a/zomes/dpki/code/src/dpki_trait/mod.rs b/zomes/dpki/code/src/dpki_trait/mod.rs index 0beb2e9..6cf1018 100644 --- a/zomes/dpki/code/src/dpki_trait/mod.rs +++ b/zomes/dpki/code/src/dpki_trait/mod.rs @@ -2,10 +2,10 @@ use crate::authorizor::handlers::handle_set_authorizor; use crate::key_registration::{handlers::handle_create_key_registration, AppKeyType}; use crate::keyset_root::handlers::{handle_get_my_keyset_root, handle_set_keyset_root}; use crate::rules::handlers::create_new_rules; +use crate::utils::handle_send_handshake_notify; +use hdk::prelude::*; use hdk::{ - error::{ZomeApiError, ZomeApiResult}, holochain_core_types::signature::Signature, - holochain_json_api::{error::JsonError, json::JsonString}, holochain_persistence_api::hash::HashString, holochain_wasm_utils::api_serialization::sign::SignOneTimeResult, AGENT_ADDRESS, @@ -55,12 +55,12 @@ pub fn init(params: String) -> ZomeApiResult { hdk::debug(format!("Initial Rules set: {:}", rules.clone()).to_string())?; } None => match init_params.first_deepkey_agent { - Some(_) => { - hdk::debug(format!("*******ToDo for FDA*************"))?; + Some(fda) => { + hdk::debug(format!("*******IMplemnting FDA*************"))?; // We need to Handshake - + handle_send_handshake_notify(Address::from(fda))?; } - None => return Err(ZomeApiError::from("Error".to_string())), + None => return Err(ZomeApiError::from("DeepKey Error: init() was successfull but you have to still handshake with your FirstDeepKeyAgent".to_string())), }, }