MCPcopy Create free account
hub / github.com/AdRoll/baker / TestCrypt

Function TestCrypt

filter/crypt_test.go:10–188  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestCrypt(t *testing.T) {
11 tests := []struct {
12 name string
13 record string
14
15 algorithm string
16 decrypt bool
17 srcField string
18 dstField string
19 algorithmConfig map[string]string
20
21 wantValue []byte
22 wantErr bool
23 }{
24 {
25 name: "encrypt",
26 record: "s3cr3t,def,ghi",
27 algorithm: "fernet",
28 decrypt: false,
29 srcField: "foo",
30 dstField: "foo",
31 algorithmConfig: map[string]string{
32 "Key": "mp5jfs_We-bngW4srQCwp7nLljXJDyuVCVw1Q8NEo_U=",
33 },
34 wantValue: []byte("s3cr3t"),
35 },
36 {
37 name: "decrypt",
38 record: "gAAAAABgAHxm_pT_mAhSxNRb2LHXHZjrIc3eoYLPJxMYGrkRsXrD39EI6fzvs-iwQpiGGesFJ9TagmlBbbhY4NlARAMAIGz90g==,def,ghi",
39 algorithm: "fernet",
40 decrypt: true,
41 srcField: "foo",
42 dstField: "foo",
43 algorithmConfig: map[string]string{
44 "Key": "mp5jfs_We-bngW4srQCwp7nLljXJDyuVCVw1Q8NEo_U=",
45 },
46 wantValue: []byte("s3cr3t"),
47 },
48 {
49 name: "decrypt with TTL",
50 record: "gAAAAABgAHxm_pT_mAhSxNRb2LHXHZjrIc3eoYLPJxMYGrkRsXrD39EI6fzvs-iwQpiGGesFJ9TagmlBbbhY4NlARAMAIGz90g==,def,ghi",
51 algorithm: "fernet",
52 decrypt: true,
53 srcField: "foo",
54 dstField: "foo",
55 algorithmConfig: map[string]string{
56 "Key": "mp5jfs_We-bngW4srQCwp7nLljXJDyuVCVw1Q8NEo_U=",
57 "TTL": "56307200000", // 200 years in seconds
58 },
59 wantValue: []byte("s3cr3t"),
60 },
61 {
62 name: "decrypt error",
63 record: "asdAAABgAHxm_pT_mAhSxNRb2LHXHZjrIc3eoYLPJxMYGrkRsXrD39EI6fzvs-iwQpiGGesFJ9TagmlBbbhY4NlARAMAIGz90g==,def,ghi",
64 algorithm: "fernet",
65 decrypt: true,
66 srcField: "foo",
67 dstField: "foo",

Callers

nothing calls this directly

Calls 7

ParseMethod · 0.95
ProcessMethod · 0.95
GetMethod · 0.95
NewCryptFunction · 0.85
fieldByNameFunction · 0.70
RunMethod · 0.65
decryptMethod · 0.65

Tested by

no test coverage detected