github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/chain_link_test.go (about) 1 package libkb 2 3 import ( 4 "testing" 5 6 keybase1 "github.com/keybase/client/go/protocol/keybase1" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func importExportLink(tc TestContext, data []byte, uid keybase1.UID) { 11 m := NewMetaContextForTest(tc) 12 linkServer, err := ImportLinkFromServer(m, nil, data, uid) 13 require.NoError(tc.T, err) 14 packed, err := linkServer.Pack() 15 require.NoError(tc.T, err) 16 packedBytes, err := packed.Marshal() 17 require.NoError(tc.T, err) 18 unpacked := NewChainLink(tc.G, nil, linkServer.id) 19 err = unpacked.unpackFromLocalStorage(m, uid, packedBytes) 20 require.NoError(tc.T, err) 21 repacked, err := unpacked.Pack() 22 require.NoError(tc.T, err) 23 repackedBytes, err := repacked.Marshal() 24 require.NoError(tc.T, err) 25 require.True(tc.T, FastByteArrayEq(packedBytes, repackedBytes)) 26 } 27 28 func TestChainLinkImport(t *testing.T) { 29 tc := SetupTest(t, "chainlinkimport", 1) 30 defer tc.Cleanup() 31 32 importExportLink(tc, []byte(linkVer1), linkUID) 33 importExportLink(tc, []byte(linkVer2), linkUID) 34 } 35 36 var linkUID = keybase1.UID("38566cd216a6c42c33134c5229452c19") 37 38 const linkVer1 = `{ 39 "seqno": 5, 40 "payload_hash": "d8c707d2f253b2bd50ed75764cf404bbbcc58ccb7246f3d6ae17828dae57f332", 41 "merkle_seqno": 98495, 42 "sig_id": "535c9f11743bc307bc6c82721f36afa519a554dd7ec36a7b7ceb77ac7d82ded70f", 43 "sig_id_short": "U1yfEXQ7wwe8bIJyHzavpRmlVN1-w2p7fOt3", 44 "kid": "0120e5b206afdd8ad09f527e79721e21024237d31db98e6cb4038d5bcc785b68b6130a", 45 "sig": "hKRib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEg5bIGr92K0J9SfnlyHiECQjfTHbmObLQDjVvMeFtothMKp3BheWxvYWTFBDx7ImJvZHkiOnsiZ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AxMjBlNWIyMDZhZmRkOGFkMDlmNTI3ZTc5NzIxZTIxMDI0MjM3ZDMxZGI5OGU2Y2I0MDM4ZDViY2M3ODViNjhiNjEzMGEifSwidHlwZSI6InN1YmtleSIsInZlcnNpb24iOjF9LCJjbGllbnQiOnsibmFtZSI6ImtleWJhc2UuaW8gZ28gY2xpZW50IiwidmVyc2lvbiI6IjEuMC40MSJ9LCJjdGltZSI6MTUxOTMxNjAwOSwiZXhwaXJlX2luIjo1MDQ1NzYwMDAsInByZXYiOiIyNzhmOWZhZmE5MTc5YWE0OWY4NTJlZTI5ODhlOTI1NWUwZjMyYmM5MjEyZTNiMTI3OWU5YTMzNmQxYTZmNTYwIiwic2Vxbm8iOjUsInRhZyI6InNpZ25hdHVyZSJ9o3NpZ8RAaFWjav1+kGe8j73ulzmDTJYSPlD2VQsRXUzX2Ch628qdnVzbg24ZuOgwPMKt8RENC9O6VCnPAhSnMfuYO86lAKhzaWdfdHlwZSCkaGFzaIKkdHlwZQildmFsdWXEICg/YL04OBin+W3+BrM9GNwSVHg9fegkZUhrARIc1tSxo3RhZ80CAqd2ZXJzaW9uAQ==", 46 "payload_json": "{\"body\":{\"device\":{\"id\":\"dd830fbcaf92ac38530993d76936ce18\",\"kid\":\"0121441e6d9bfa1ec7f2c9e245b3c23f6fd9544a9050b86a54cfb82c5cd2c4b099300a\",\"status\":1},\"key\":{\"eldest_kid\":\"012057bd86a5c2a8e5e0ba228021b49216e38158ce04abba069fe9b3c2298d283a600a\",\"host\":\"keybase.io\",\"kid\":\"0120e5b206afdd8ad09f527e79721e21024237d31db98e6cb4038d5bcc785b68b6130a\",\"uid\":\"38566cd216a6c42c33134c5229452c19\",\"username\":\"testuser1874\"},\"merkle_root\":{\"ctime\":1519316009,\"hash\":\"d72310ef2f72ff038c09a8fa7db61f88d1b77d4c3ddc381425471949c298c222f71cfee809663f4278144efa6f58af28c763e9f34e4ac538404da3d2e97f2fc9\",\"hash_meta\":\"672317854de0a828b2389c871612fd00222f037bdcb3351ee5a64385f1e0facb\",\"seqno\":98494},\"subkey\":{\"kid\":\"0121441e6d9bfa1ec7f2c9e245b3c23f6fd9544a9050b86a54cfb82c5cd2c4b099300a\",\"parent_kid\":\"0120e5b206afdd8ad09f527e79721e21024237d31db98e6cb4038d5bcc785b68b6130a\"},\"type\":\"subkey\",\"version\":1},\"client\":{\"name\":\"keybase.io go client\",\"version\":\"1.0.41\"},\"ctime\":1519316009,\"expire_in\":504576000,\"prev\":\"278f9fafa9179aa49f852ee2988e9255e0f32bc9212e3b1279e9a336d1a6f560\",\"seqno\":5,\"tag\":\"signature\"}", 47 "sig_type": 1, 48 "sig_version": 1, 49 "ctime": 1519316009, 50 "etime": 2023892009, 51 "rtime": null, 52 "eldest_seqno": 1, 53 "sig_status": 0, 54 "prev": "278f9fafa9179aa49f852ee2988e9255e0f32bc9212e3b1279e9a336d1a6f560", 55 "proof_id": null, 56 "proof_type": null, 57 "proof_text_check": null, 58 "proof_text_full": null, 59 "check_data_json": null, 60 "remote_id": null, 61 "api_url": null, 62 "human_url": null, 63 "proof_state": null, 64 "proof_status": null, 65 "retry_count": null, 66 "hard_fail_count": null, 67 "last_check": null, 68 "last_success": null, 69 "version": null, 70 "fingerprint": "", 71 "si1" : "aFWjav1+kGe8j73ulzmDTJYSPlD2VQsRXUzX2Ch628qdnVzbg24ZuOgwPMKt8RENC9O6VCnPAhSnMfuYO86lAA==" 72 }` 73 74 const linkVer2 = `{ 75 "seqno": 6, 76 "payload_hash": "63a09ace5f83816e96ae96f9d2869912987ffd62bd3fab6f256fc873f01f4205", 77 "merkle_seqno": 98496, 78 "sig_id": "28335497e87230131e3f1473dd98accd21d4329a420bf970833fa5a60127d1610f", 79 "sig_id_short": "KDNUl-hyMBMePxRz3ZiszSHUMppCC_lwgz-l", 80 "kid": "012057bd86a5c2a8e5e0ba228021b49216e38158ce04abba069fe9b3c2298d283a600a", 81 "sig": "hKRib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEgV72GpcKo5eC6IoAhtJIW44FYzgSrugaf6bPCKY0oOmAKp3BheWxvYWTESpcCBsQg2McH0vJTsr1Q7XV2TPQEu7zFjMtyRvPWrheCja5X8zLEIPqyUjccwO63+bVojYys2Jy6K1c1d5BdO5LuwfloA8MxAwHCo3NpZ8RAg38rHEmvaUJHc3QGMqx8tZCDjxi2z1e7c+9brX1WWbqSHOLXDY+hRsnSkPNv7MfnrOK6hjzww/udG30iQYvEDqhzaWdfdHlwZSCkaGFzaIKkdHlwZQildmFsdWXEIFyjQhLjrdVvb2nv98JI5/nebzxDH17MpGIEZ0dleTJko3RhZ80CAqd2ZXJzaW9uAQ==", 82 "payload_json": "{\"body\":{\"key\":{\"eldest_kid\":\"012057bd86a5c2a8e5e0ba228021b49216e38158ce04abba069fe9b3c2298d283a600a\",\"host\":\"keybase.io\",\"kid\":\"012057bd86a5c2a8e5e0ba228021b49216e38158ce04abba069fe9b3c2298d283a600a\",\"uid\":\"38566cd216a6c42c33134c5229452c19\",\"username\":\"testuser1874\"},\"merkle_root\":{\"ctime\":1519316009,\"hash\":\"b8447dbc02e6e58a69827207c5d7aa09bb77b5cf0129a49e39738c96d9ad757434249d610b2b9099f2c3385c249bdce0fb27b27e661f527e20ad083742000cc3\",\"hash_meta\":\"4eb194235868bbdc2eb2416d4365bc70378ce7edbc132dcc5b37b8c2cc79fa54\",\"seqno\":98495},\"track\":{\"basics\":{\"id_version\":0,\"last_id_change\":1519314299,\"username\":\"followtest92652\"},\"id\":\"6c01fd886268fd6df8185cac265ca819\",\"remote_proofs\":[],\"seq_tail\":null},\"type\":\"track\",\"version\":2},\"client\":{\"name\":\"keybase.io go client\",\"version\":\"1.0.41\"},\"ctime\":1519316042,\"expire_in\":504576000,\"prev\":\"d8c707d2f253b2bd50ed75764cf404bbbcc58ccb7246f3d6ae17828dae57f332\",\"seqno\":6,\"tag\":\"signature\"}", 83 "sig_type": 3, 84 "sig_version": 2, 85 "ctime": 1519316042, 86 "etime": 2023892042, 87 "rtime": null, 88 "eldest_seqno": 1, 89 "sig_status": 0, 90 "prev": "d8c707d2f253b2bd50ed75764cf404bbbcc58ccb7246f3d6ae17828dae57f332", 91 "proof_id": null, 92 "proof_type": null, 93 "proof_text_check": null, 94 "proof_text_full": null, 95 "check_data_json": null, 96 "remote_id": null, 97 "api_url": null, 98 "human_url": null, 99 "proof_state": null, 100 "proof_status": null, 101 "retry_count": null, 102 "hard_fail_count": null, 103 "last_check": null, 104 "last_success": null, 105 "version": null, 106 "fingerprint": "", 107 "si2" : "k8RAg38rHEmvaUJHc3QGMqx8tZCDjxi2z1e7c+9brX1WWbqSHOLXDY+hRsnSkPNv7MfnrOK6hjzww/udG30iQYvEDpcCBsDAAwHCBw==" 108 }`