-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathapproval_request_test.go
65 lines (47 loc) · 1.67 KB
/
approval_request_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
package authy
import (
"net/url"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func Test_SendApprovalRequest(t *testing.T) {
c := require.New(t)
api := newAPI()
user, err := api.RegisterUser("foo@example.com", 1, "432-123-1211", url.Values{})
approvalRequest, err := api.SendApprovalRequest(user.ID, "please approve this", Details{"data1": "value1"}, url.Values{})
c.Nil(err)
c.NotNil(approvalRequest)
c.True(approvalRequest.Valid())
}
func Test_FindApprovalRequest(t *testing.T) {
c := require.New(t)
api := newAPI()
user, err := api.RegisterUser("foo@example.com", 1, "432-123-1131", url.Values{})
approvalRequest, err := api.SendApprovalRequest(user.ID, "please approve this", Details{"data1": "value1"}, url.Values{})
c.Nil(err)
c.True(approvalRequest.Valid())
uuid := approvalRequest.UUID
approvalRequest, err = api.FindApprovalRequest(uuid, url.Values{})
c.Nil(err)
c.Equal(OneTouchStatusPending, approvalRequest.Status)
c.Equal(uuid, approvalRequest.UUID)
}
func Test_WaitForApprovalRequest(t *testing.T) {
c := require.New(t)
api := newAPI()
user, err := api.RegisterUser("foo@example.com", 1, "432-123-1114", url.Values{})
c.Nil(err)
c.NotNil(user)
approvalRequest, err := api.SendApprovalRequest(user.ID, "please approve this", Details{"data1": "value1"}, url.Values{})
c.Nil(err)
c.NotNil(approvalRequest)
c.True(approvalRequest.Valid())
now := time.Now()
maxDuration := 2 * time.Second
status, err := api.WaitForApprovalRequest(approvalRequest.UUID, maxDuration, url.Values{"user_ip": {"234.78.25.2"}})
c.Nil(err)
elapsedTime := time.Since(now)
c.True(elapsedTime < maxDuration+(1*time.Second))
c.Equal(status, OneTouchStatusExpired)
}