blob: 8f638b35e7c3ab475ea76b8f8c0d0637634262f1 [file] [log] [blame]
gio36b23b32024-08-25 12:20:54 +04001package installer
2
3import (
4 "testing"
5)
6
7type testKeyGen struct{}
8
gio864b4332024-09-05 13:56:47 +04009func (g testKeyGen) GenerateAuthKey(username string) (string, error) {
gio36b23b32024-08-25 12:20:54 +040010 return username, nil
11}
12
gio864b4332024-09-05 13:56:47 +040013func (g testKeyGen) ExpireKey(username, key string) error {
14 return nil
15}
16
17func (g testKeyGen) ExpireNode(username, node string) error {
18 return nil
19}
20
21func (g testKeyGen) RemoveNode(username, node string) error {
22 return nil
23}
24
gio36b23b32024-08-25 12:20:54 +040025func TestDeriveVPNAuthKey(t *testing.T) {
26 schema := structSchema{
27 "input",
28 []Field{
29 Field{"username", basicSchema{"username", KindString, false, nil}},
30 Field{"authKey", basicSchema{"authKey", KindVPNAuthKey, false, map[string]string{
31 "usernameField": "username",
32 }}},
33 },
34 false,
35 }
36 input := map[string]any{
37 "username": "foo",
38 }
39 v, err := deriveValues(input, input, schema, nil, testKeyGen{})
40 if err != nil {
41 t.Fatal(err)
42 }
43 if key, ok := v["authKey"].(string); !ok || key != "foo" {
44 t.Fatal(v)
45 }
46}