MCPcopy
hub / github.com/getsops/sops / TestEncryptedRegex

Function TestEncryptedRegex

sops_test.go:162–212  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

160}
161
162func TestEncryptedRegex(t *testing.T) {
163 branches := TreeBranches{
164 TreeBranch{
165 TreeItem{
166 Key: "enc:foo",
167 Value: "bar",
168 },
169 TreeItem{
170 Key: "bar",
171 Value: TreeBranch{
172 TreeItem{
173 Key: "foo",
174 Value: "bar",
175 },
176 },
177 },
178 },
179 }
180 tree := Tree{Branches: branches, Metadata: Metadata{EncryptedRegex: "^enc:"}}
181 expected := TreeBranch{
182 TreeItem{
183 Key: "enc:foo",
184 Value: "rab",
185 },
186 TreeItem{
187 Key: "bar",
188 Value: TreeBranch{
189 TreeItem{
190 Key: "foo",
191 Value: "bar",
192 },
193 },
194 },
195 }
196 cipher := reverseCipher{}
197 _, err := tree.Encrypt(bytes.Repeat([]byte("f"), 32), cipher)
198 if err != nil {
199 t.Errorf("Encrypting the tree failed: %s", err)
200 }
201 if !reflect.DeepEqual(tree.Branches[0], expected) {
202 t.Errorf("Trees don't match: \ngot \t\t%+v,\n expected \t\t%+v", tree.Branches[0], expected)
203 }
204 _, err = tree.Decrypt(bytes.Repeat([]byte("f"), 32), cipher)
205 if err != nil {
206 t.Errorf("Decrypting the tree failed: %s", err)
207 }
208 expected[0].Value = "bar"
209 if !reflect.DeepEqual(tree.Branches[0], expected) {
210 t.Errorf("Trees don't match: \ngot\t\t\t%+v,\nexpected\t\t%+v", tree.Branches[0], expected)
211 }
212}
213
214func TestUnencryptedRegex(t *testing.T) {
215 branches := TreeBranches{

Callers

nothing calls this directly

Calls 2

EncryptMethod · 0.95
DecryptMethod · 0.95

Tested by

no test coverage detected