-
Notifications
You must be signed in to change notification settings - Fork 95
/
testutils.go
82 lines (78 loc) · 3.56 KB
/
testutils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"bytes"
"log"
"os"
"path/filepath"
"testing"
)
func setupLogBuffer(t *testing.T, cfg *config) *bytes.Buffer {
if err := cfg.setupLogging(); err != nil {
t.Fatalf("Failed to setup logging: %v", err)
}
buffer := &bytes.Buffer{}
log.SetOutput(buffer)
return buffer
}
// Static keys, only used in tests, to speed them up by not having to generate new keys every time.
const (
testRSAKey = `-----BEGIN PRIVATE KEY-----
MIIG/wIBADANBgkqhkiG9w0BAQEFAASCBukwggblAgEAAoIBgQCzbvOhNjkuPy3P
twRV64pEgU07dSJqQlxkS/Ame6tK/Ek/6bMPN0/o+7hm7SCse3psh+4oZ7Bay9lk
DGA0/D8Z/OTNlB/kfXfEEPlk02M3ts5o4EULoM+0E9BnE74ZYb0XWwL0tqewuTlT
2SE13beQ/YXjn96B5+YFHWcBLow5QLLRshax4pVqaPQNyIspfi1p9P8ZirVpa/ia
62khyrScZbmutqW+bjJ4b1khjRFIdWuMsz+XqfwxSJCxYgdNFOKuLheWr6yIPPYK
iLYltmTJ4Xf62RJtCl6UsYs54Y8Bc57AITzBGw+uQ0QKcLaoBIvAssp9+eycNFJD
baWLZLN345CET3j69b8wwNs9g+GAi1oeFLMabkRUbrk6VPdC48jOAbe3PjM68E4z
iaSLgjHwDICucb0kXlmYALhymTS4VCkLnTNlgYUJDvWMjNs/PT+21C9fiFz/+LXG
lGA5Rjtr/SEPFjtfjiMAtpvgt7xMKWThSiDRzulWF7TRIB8v0e8CAwEAAQKCAYEA
pwfetTBztDBN5fFZkN3tXW38Rh/5BG938EmcaUZwIyKM0X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60up0tAA8X0IxCxE6kLlL4GGF5U80PMxRKzy//lyyZT/JKDS5aoE0gEc
RfpGlqUWWWRTOusIdut7YPgT0AyKGmuuIIGgkFnMDi01rXouQ43iGwimsiWidW92
u6DK/5XRdoRWPAp6WBB9+oDSOaDaCqh/2DVKXvDnkRTRO0b7wtkr0toFBZBJz/Iw
f+ilgdoo5144IizpAoHADaYgSIcyroN9yPRtAPm1f8fNMM9jd2kPqqlGh1cYFJZB
dY1rQPFeaSvgOp6uv7p+uEeRQ2NNFWwxBDPXvFOP+okiflYXHLLAfw1narFI0FD9
sm3m6vB8p9StSRr38knC4HLkISHy9WX2YaMCmjmdcutK+J58EXNXgnT/JZ2vam57
hzpjdZoCzZg08iDt7wBMwhnph0iCjDM9fzZ9m3Srvn1mDC1P8NkbHaNeQA1IRO74
nIZ/bxpgyMasawa8Gg8zAoHBAIpgicQn4eR1DexwcUTiPgoXbhqgyirNR31MhfWO
7ZUla6H+XPqni9u+2FlKZMn2wuooTR746yoUaklcYIncemZZczjU8jz+yXODkGU/
LnUH0xMlGfEImI8LeuM670I/N2/29SxABsE6RlJULcZrj6jqZKURsC6uYEfKhc5n
dwG0LCp3MvNN4+XvTWBGq2YyNkF43goXG4myV70tkMS8BJGgWT7ID6niuTw8mdUu
qtfwiyotqKKmXeyJWEqJ56B7lw==
-----END PRIVATE KEY-----`
testECDSAKey = `-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgcPlksxvJRBMC7H70
xGOaGRgody4vm36E2Zm8/UbyVMShRANCAATaM4DFbeUO0JFkUTlUPIhhD9II3391
bdnZwRL5hG1CZw7oVWsCfgm3ujpToKFqAz22AVQees07AV9cICpx+i21
-----END PRIVATE KEY-----`
testEd25519Key = `-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIIpRrU9cXkMb3/c/H1oAAQpnnS6PXrWJe1jvYo6pSxNw
-----END PRIVATE KEY-----`
)
func writeTestKeys(t *testing.T, dataDir string) {
for fileName, content := range map[string]string{
"host_rsa_key": testRSAKey,
"host_ecdsa_key": testECDSAKey,
"host_ed25519_key": testEd25519Key,
} {
if err := os.WriteFile(filepath.Join(dataDir, fileName), []byte(content), 0600); err != nil {
t.Fatal(err)
}
}
}