-
Notifications
You must be signed in to change notification settings - Fork 1
/
authkey_test.go
95 lines (84 loc) · 1.91 KB
/
authkey_test.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
83
84
85
86
87
88
89
90
91
92
93
94
95
package apns
import (
"os"
"testing"
)
func TestAuthKeyNoSuchFile(t *testing.T) {
_, err := AuthKeyFromFile("")
if err.Error() != "open : no such file or directory" {
t.Errorf("got: %q; want: %q", err, "open : no such file or directory")
}
}
func TestAuthKeyBadPEM(t *testing.T) {
names := []string{
"testdata/AuthKeyBadPEM_1.p8",
"testdata/AuthKeyBadPEM_2.p8",
}
for _, name := range names {
_, err := AuthKeyFromFile(name)
if err != nil {
if err != ErrAuthKeyBadPEM {
t.Errorf("%v: got: %q; want: ErrAuthKeyBadPEM", name, err)
}
} else {
t.Errorf("%v: want not nil err", name)
}
}
}
func TestAuthKeyBadPKCS8(t *testing.T) {
names := []string{
"testdata/AuthKeyBadPKCS8_1.p8",
"testdata/AuthKeyBadPKCS8_2.p8",
}
for _, name := range names {
_, err := AuthKeyFromFile(name)
if err != nil {
if err != ErrAuthKeyBadPKCS8 {
t.Errorf("%v: got: %q; want ErrAuthKeyBadPKCS8", name, err)
}
} else {
t.Errorf("%v: want not nil err", name)
}
}
}
func TestAuthKeyNotECDSA256(t *testing.T) {
names := []string{
"testdata/AuthKeyRSA.p8",
"testdata/AuthKeyED25519.p8",
"testdata/AuthKeyECDSAP224.p8",
}
for _, name := range names {
_, err := AuthKeyFromFile(name)
if err != nil {
if err != ErrAuthKeyNotECDSAP256 {
t.Errorf("%v: got: %q; want ErrAuthKeyNotECDSAP256", name, err)
}
} else {
t.Errorf("%v: want not nil err", name)
}
}
}
func TestAuthKey(t *testing.T) {
key, err := AuthKeyFromFile("testdata/AuthKey_5MDQ4KLTY7.p8")
if err != nil {
t.Error(err)
}
if key == nil {
t.Error("want not nil key")
}
}
func BenchmarkAuthKeyFromBytes(b *testing.B) {
file, err := os.ReadFile("testdata/AuthKey_5MDQ4KLTY7.p8")
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
AuthKeyFromBytes(file)
}
}
func BenchmarkAuthKeyFromFile(b *testing.B) {
for i := 0; i < b.N; i++ {
AuthKeyFromFile("testdata/AuthKey_5MDQ4KLTY7.p8")
}
}