This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
pullzone_set_force_ssl_test.go
79 lines (61 loc) · 2.03 KB
/
pullzone_set_force_ssl_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
//go:build integrationtest
// +build integrationtest
package bunny_test
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
bunny "github.com/simplesurance/bunny-go"
)
func TestSetForceSSL(t *testing.T) {
ctx := context.Background()
clt := newClient(t)
pzAddopts := bunny.PullZoneAddOptions{
Name: randomResourceName("pullzone"),
OriginURL: "http://bunny.net",
}
pz := createPullZone(t, clt, &pzAddopts)
hostname := "testhostname-" + uuid.New().String() + ".bunnytftest.de"
err := clt.PullZone.AddCustomHostname(ctx, *pz.ID, &bunny.AddCustomHostnameOptions{Hostname: &hostname})
require.NoError(t, err, "add hostname to pull zone failed")
trueVal := true
err = clt.PullZone.SetForceSSL(ctx, *pz.ID, &bunny.SetForceSSLOptions{
Hostname: &hostname,
ForceSSL: &trueVal,
})
require.NoError(t, err, "enabling force ssl failed")
pz, err = clt.PullZone.Get(ctx, *pz.ID)
require.NoError(t, err, "retrieving pull zone failed")
assertHostnameForceSSLValue(t, pz.Hostnames, hostname, true)
falseVal := false
err = clt.PullZone.SetForceSSL(ctx, *pz.ID, &bunny.SetForceSSLOptions{
Hostname: &hostname,
ForceSSL: &falseVal,
})
require.NoError(t, err, "enabling force ssl failed")
pz, err = clt.PullZone.Get(ctx, *pz.ID)
require.NoError(t, err, "retrieving pull zone failed")
assertHostnameForceSSLValue(t, pz.Hostnames, hostname, false)
}
func assertHostnameForceSSLValue(t *testing.T, hostnames []*bunny.Hostname, hostname string, expectedForceSSLVal bool) {
t.Helper()
for _, elem := range hostnames {
if elem.Value == nil {
t.Errorf("hostname entry has nil Value field")
continue
}
if *elem.Value == hostname {
if elem.ForceSSL == nil {
t.Errorf("hostname entry has nil ForceSSL field")
return
}
if *elem.ForceSSL != expectedForceSSLVal {
t.Errorf("expected %v ForceSSL value, got %v, for hostname %q", expectedForceSSLVal, *elem.ForceSSL, hostname)
return
}
return
}
}
t.Errorf("hostname %q not found in hostnames slices", hostname)
}