MCPcopy Create free account
hub / github.com/encodeous/nylon / TestBundleInvalidSign

Function TestBundleInvalidSign

state/distribution_test.go:111–152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

109}
110
111func TestBundleInvalidSign(t *testing.T) {
112 root := GenerateKey()
113 fakePriv := GenerateKey()
114 cfg := CentralCfg{
115 Dist: nil,
116 Routers: make([]RouterCfg, 0),
117 Clients: []ClientCfg{
118 {NodeCfg{
119 Id: "blah",
120 PubKey: NyPublicKey{},
121 }},
122 },
123 Graph: []string{
124 "blah, blah",
125 "a = blah",
126 "b = a",
127 "a, b",
128 },
129 Timestamp: 0,
130 }
131 cfg.Timestamp = time.Now().UnixNano()
132
133 plainText, err := yaml.Marshal(cfg)
134 assert.NoError(t, err)
135 privKey := x25519.PrivateKey(fakePriv[:])
136 sig, err := privKey.Sign(rand.Reader, plainText, crypto.Hash(0))
137 assert.NoError(t, err)
138
139 plainBundle := append(sig, plainText...)
140
141 pk := root.Pubkey()
142 ahead, err := chacha20poly1305.NewX(pk[:])
143 assert.NoError(t, err)
144 nonce := make([]byte, chacha20poly1305.NonceSizeX)
145 _, err = rand.Read(nonce)
146 assert.NoError(t, err)
147 cipherText := ahead.Seal(make([]byte, 0), nonce, plainBundle, make([]byte, 0))
148 bundle := base64.StdEncoding.EncodeToString(append(nonce, cipherText...))
149
150 _, err = UnbundleConfig(bundle, root.Pubkey())
151 assert.ErrorContains(t, err, "invalid signature")
152}
153
154func TestBundleInvalidData1(t *testing.T) {
155 root := GenerateKey()

Callers

nothing calls this directly

Calls 4

GenerateKeyFunction · 0.85
UnbundleConfigFunction · 0.85
PubkeyMethod · 0.80
ReadMethod · 0.65

Tested by

no test coverage detected