Skip to content

Commit 4d54176

Browse files
Adds authorization testing
1 parent 31ae3b0 commit 4d54176

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Tests/GraphQLWSTests/GraphQLWSTests.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,34 @@ class GraphqlWsTests: XCTestCase {
4242
)
4343
}
4444

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+
4573
func testSingleOp() throws {
4674
let id = UUID().description
4775

@@ -140,4 +168,8 @@ class GraphqlWsTests: XCTestCase {
140168
"Messages: \(messages.description)"
141169
)
142170
}
171+
172+
enum TestError: Error {
173+
case couldBeAnything
174+
}
143175
}

0 commit comments

Comments
 (0)