-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Fabian Jucker <[email protected]>
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package vals | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestValues_OnePasswordConnect_EvalTemplate(t *testing.T) { | ||
// TODO | ||
// create vault and item for testing | ||
// op vault create vals-test | ||
// op item create --vault vals-test --title=vals-test [email protected] password=secret --category=login | ||
|
||
// Pre-requisite: | ||
// Setup 1Password connect service with access to `vals-test` vault: https://developer.1password.com/docs/connect/ | ||
|
||
// set up service principal credentials in the environment: | ||
// "OP_CONNECT_TOKEN": "...", | ||
// "OP_CONNECT_HOST": "...", | ||
|
||
type testcase struct { | ||
template map[string]interface{} | ||
expected map[string]interface{} | ||
} | ||
vaultLabel := "vals-test" | ||
itemLabel := "vals-test" | ||
|
||
testcases := []testcase{ | ||
{ | ||
template: map[string]interface{}{ | ||
"foo": "FOO", | ||
"username": fmt.Sprintf("ref+onepasswordconnect://%s/%s#/username", vaultLabel, itemLabel), | ||
"password": fmt.Sprintf("ref+onepasswordconnect://%s/%s#/password", vaultLabel, itemLabel), | ||
}, | ||
expected: map[string]interface{}{ | ||
"foo": "FOO", | ||
"username": "[email protected]", | ||
"password": "secret", | ||
}, | ||
}, | ||
} | ||
|
||
for i := range testcases { | ||
tc := testcases[i] | ||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { | ||
vals, err := Eval(tc.template) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
diff := cmp.Diff(tc.expected, vals) | ||
if diff != "" { | ||
t.Errorf("unxpected diff: %s", diff) | ||
} | ||
}) | ||
} | ||
} |