blob: 7a3415453bcaf46ca0695233b517113c7443824c [file] [log] [blame]
gio36b23b32024-08-25 12:20:54 +04001package installer
2
3import (
4 "testing"
5)
6
7type testKeyGen struct{}
8
9func (g testKeyGen) Generate(username string) (string, error) {
10 return username, nil
11}
12
13func TestDeriveVPNAuthKey(t *testing.T) {
14 schema := structSchema{
15 "input",
16 []Field{
17 Field{"username", basicSchema{"username", KindString, false, nil}},
18 Field{"authKey", basicSchema{"authKey", KindVPNAuthKey, false, map[string]string{
19 "usernameField": "username",
20 }}},
21 },
22 false,
23 }
24 input := map[string]any{
25 "username": "foo",
26 }
27 v, err := deriveValues(input, input, schema, nil, testKeyGen{})
28 if err != nil {
29 t.Fatal(err)
30 }
31 if key, ok := v["authKey"].(string); !ok || key != "foo" {
32 t.Fatal(v)
33 }
34}