File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,34 @@ class GraphqlWsTests: XCTestCase {
42
42
)
43
43
}
44
44
45
+ /// Tests that throwing in the authorization callback forces an unauthorized error
46
+ func testAuth( ) throws {
47
+ server. auth { payload in
48
+ throw TestError . couldBeAnything
49
+ }
50
+
51
+ var messages = [ String] ( )
52
+ let completeExpectation = XCTestExpectation ( )
53
+
54
+ let client = Client ( messenger: clientMessenger)
55
+ client. onMessage { message in
56
+ messages. append ( message)
57
+ completeExpectation. fulfill ( )
58
+ }
59
+
60
+ client. sendConnectionInit (
61
+ payload: ConnectionInitAuth (
62
+ authToken: " "
63
+ )
64
+ )
65
+
66
+ wait ( for: [ completeExpectation] , timeout: 2 )
67
+ XCTAssertEqual (
68
+ messages,
69
+ [ " 4401: Unauthorized " ]
70
+ )
71
+ }
72
+
45
73
func testSingleOp( ) throws {
46
74
let id = UUID ( ) . description
47
75
@@ -140,4 +168,8 @@ class GraphqlWsTests: XCTestCase {
140
168
" Messages: \( messages. description) "
141
169
)
142
170
}
171
+
172
+ enum TestError : Error {
173
+ case couldBeAnything
174
+ }
143
175
}
You can’t perform that action at this time.
0 commit comments