@@ -84,6 +84,8 @@ func TestAllocationLifeTime(t *testing.T) {
84
84
staticKey , err := nonceHash .Generate ()
85
85
assert .NoError (t , err )
86
86
87
+ authSuccessCallbackTimes := 0
88
+
87
89
r := Request {
88
90
AllocationManager : allocationManager ,
89
91
NonceHash : nonceHash ,
@@ -93,13 +95,16 @@ func TestAllocationLifeTime(t *testing.T) {
93
95
AuthHandler : func (string , string , net.Addr ) (key []byte , ok bool ) {
94
96
return []byte (staticKey ), true
95
97
},
98
+
99
+ AuthSuccess : func (username string , realm string , srcAddr net.Addr ) {
100
+ authSuccessCallbackTimes ++
101
+ },
96
102
}
97
103
98
104
fiveTuple := & allocation.FiveTuple {SrcAddr : r .SrcAddr , DstAddr : r .Conn .LocalAddr (), Protocol : allocation .UDP }
99
105
100
106
_ , err = r .AllocationManager .CreateAllocation (fiveTuple , r .Conn , 0 , time .Hour )
101
107
assert .NoError (t , err )
102
-
103
108
assert .NotNil (t , r .AllocationManager .GetAllocation (fiveTuple ))
104
109
105
110
m := & stun.Message {}
@@ -109,7 +114,12 @@ func TestAllocationLifeTime(t *testing.T) {
109
114
assert .NoError (t , (stun .Realm (staticKey )).AddTo (m ))
110
115
assert .NoError (t , (stun .Username (staticKey )).AddTo (m ))
111
116
117
+ assert .NoError (t , handleCreatePermissionRequest (r , m ))
118
+ assert .Equal (t , 1 , authSuccessCallbackTimes )
119
+
112
120
assert .NoError (t , handleRefreshRequest (r , m ))
121
+ assert .Equal (t , 2 , authSuccessCallbackTimes )
122
+
113
123
assert .Nil (t , r .AllocationManager .GetAllocation (fiveTuple ))
114
124
})
115
125
}
0 commit comments