| gio | 36b23b3 | 2024-08-25 12:20:54 +0400 | [diff] [blame] | 1 | package installer |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | ) |
| 6 | |
| 7 | type testKeyGen struct{} |
| 8 | |
| 9 | func (g testKeyGen) Generate(username string) (string, error) { |
| 10 | return username, nil |
| 11 | } |
| 12 | |
| 13 | func 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 | } |