...
1 package wfe2
2
3 import (
4 "net/http"
5 "testing"
6 "time"
7
8 "github.com/jmhodges/clock"
9 "github.com/letsencrypt/boulder/core"
10 corepb "github.com/letsencrypt/boulder/core/proto"
11 "github.com/letsencrypt/boulder/test"
12 "github.com/letsencrypt/boulder/web"
13 "google.golang.org/protobuf/types/known/timestamppb"
14 )
15
16 func TestRequiredStale(t *testing.T) {
17 testCases := []struct {
18 name string
19 req *http.Request
20 logEvent *web.RequestEvent
21 expectRequired bool
22 }{
23 {
24 name: "not GET",
25 req: &http.Request{Method: http.MethodPost},
26 logEvent: &web.RequestEvent{},
27 expectRequired: false,
28 },
29 {
30 name: "GET, not getAPIPrefix",
31 req: &http.Request{Method: http.MethodGet},
32 logEvent: &web.RequestEvent{},
33 expectRequired: false,
34 },
35 {
36 name: "GET, getAPIPrefix",
37 req: &http.Request{Method: http.MethodGet},
38 logEvent: &web.RequestEvent{Endpoint: getAPIPrefix + "whatever"},
39 expectRequired: true,
40 },
41 }
42
43 for _, tc := range testCases {
44 t.Run(tc.name, func(t *testing.T) {
45 test.AssertEquals(t, requiredStale(tc.req, tc.logEvent), tc.expectRequired)
46 })
47 }
48 }
49
50 func TestSaleEnoughToGETOrder(t *testing.T) {
51 fc := clock.NewFake()
52 wfe := WebFrontEndImpl{clk: fc, staleTimeout: time.Minute * 30}
53 fc.Add(time.Hour * 24)
54 created := fc.Now()
55 fc.Add(time.Hour)
56 prob := wfe.staleEnoughToGETOrder(&corepb.Order{
57 CreatedNS: created.UnixNano(),
58 Created: timestamppb.New(created),
59 })
60 test.Assert(t, prob == nil, "wfe.staleEnoughToGETOrder returned a non-nil problem")
61 }
62
63 func TestStaleEnoughToGETAuthzDeactivated(t *testing.T) {
64 fc := clock.NewFake()
65 wfe := WebFrontEndImpl{
66 clk: fc,
67 staleTimeout: time.Minute * 30,
68 pendingAuthorizationLifetime: 7 * 24 * time.Hour,
69 authorizationLifetime: 30 * 24 * time.Hour,
70 }
71 fc.Add(time.Hour * 24)
72 expires := fc.Now().Add(wfe.authorizationLifetime)
73 fc.Add(time.Hour)
74 prob := wfe.staleEnoughToGETAuthz(&corepb.Authorization{
75 Status: string(core.StatusDeactivated),
76 ExpiresNS: expires.UnixNano(),
77 Expires: timestamppb.New(expires),
78 })
79 test.Assert(t, prob == nil, "wfe.staleEnoughToGETOrder returned a non-nil problem")
80 }
81
View as plain text