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

Function TestUnencryptedRegex

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

Source from the content-addressed store, hash-verified

212}
213
214func TestUnencryptedRegex(t *testing.T) {
215 branches := TreeBranches{
216 TreeBranch{
217 TreeItem{
218 Key: "dec:foo",
219 Value: "bar",
220 },
221 TreeItem{
222 Key: "dec:bar",
223 Value: TreeBranch{
224 TreeItem{
225 Key: "foo",
226 Value: "bar",
227 },
228 },
229 },
230 },
231 }
232 tree := Tree{Branches: branches, Metadata: Metadata{UnencryptedRegex: "^dec:"}}
233 expected := TreeBranch{
234 TreeItem{
235 Key: "dec:foo",
236 Value: "bar",
237 },
238 TreeItem{
239 Key: "dec:bar",
240 Value: TreeBranch{
241 TreeItem{
242 Key: "foo",
243 Value: "bar",
244 },
245 },
246 },
247 }
248 cipher := reverseCipher{}
249
250 _, err := tree.Encrypt(bytes.Repeat([]byte("f"), 32), cipher)
251 if err != nil {
252 t.Errorf("Encrypting the tree failed: %s", err)
253 }
254 // expected[1].Value[] = "bar"
255 if !reflect.DeepEqual(tree.Branches[0], expected) {
256 t.Errorf("Trees don't match: \ngot \t\t%+v,\n expected \t\t%+v", tree.Branches[0], expected)
257 }
258 _, err = tree.Decrypt(bytes.Repeat([]byte("f"), 32), cipher)
259 if err != nil {
260 t.Errorf("Decrypting the tree failed: %s", err)
261 }
262 if !reflect.DeepEqual(tree.Branches[0], expected) {
263 t.Errorf("Trees don't match: \ngot\t\t\t%+v,\nexpected\t\t%+v", tree.Branches[0], expected)
264 }
265}
266
267func TestMACOnlyEncrypted(t *testing.T) {
268 branches := TreeBranches{

Callers

nothing calls this directly

Calls 2

EncryptMethod · 0.95
DecryptMethod · 0.95

Tested by

no test coverage detected