@@ -108,12 +108,51 @@ class AuthenticationTests: XCTestCase {
108
108
waitForExpectations ( timeout: 0.5 )
109
109
}
110
110
111
- func testAuthorizationUsingSomethingConformingToTheAuthRequestBuilderProtocol ( ) {
111
+ func testAuthorizationUsingSomethingConformingToTheDeprecatedAuthRequestBuilderProtocol ( ) {
112
112
113
113
class AuthRequestBuilder : AuthRequestBuilderProtocol {
114
- func requestFor( socketID: String , channel : PusherChannel ) -> URLRequest ? {
114
+ func requestFor( socketID: String , channelName : String ) -> URLRequest ? {
115
115
var request = URLRequest ( url: URL ( string: " http://localhost:9292/builder " ) !)
116
116
request. httpMethod = " POST "
117
+ request. httpBody = " socket_id= \( socketID) &channel_name= \( channelName) " . data ( using: String . Encoding. utf8)
118
+ request. addValue ( " myToken " , forHTTPHeaderField: " Authorization " )
119
+ return request
120
+ }
121
+ }
122
+
123
+ let ex = expectation ( description: " the channel should be subscribed to successfully " )
124
+ let channelName = " private-test-channel "
125
+
126
+ let dummyDelegate = DummyDelegate ( )
127
+ dummyDelegate. ex = ex
128
+ dummyDelegate. testingChannelName = channelName
129
+
130
+ let options = PusherClientOptions (
131
+ authMethod: AuthMethod . authRequestBuilder ( authRequestBuilder: AuthRequestBuilder ( ) )
132
+ )
133
+ pusher = Pusher ( key: " testKey123 " , options: options)
134
+ pusher. delegate = dummyDelegate
135
+ socket. delegate = pusher. connection
136
+ pusher. connection. socket = socket
137
+
138
+ let jsonData = " { \" auth \" : \" testKey123:12345678gfder78ikjbg \" } " . data ( using: String . Encoding. utf8, allowLossyConversion: false ) !
139
+ let urlResponse = HTTPURLResponse ( url: URL ( string: " http://localhost:9292/builder?channel_name=private-test-channel&socket_id=45481.3166671 " ) !, statusCode: 200 , httpVersion: nil , headerFields: nil )
140
+ MockSession . mockResponse = ( jsonData, urlResponse: urlResponse, error: nil )
141
+ pusher. connection. URLSession = MockSession . shared
142
+
143
+ let chan = pusher. subscribe ( " private-test-channel " )
144
+ XCTAssertFalse ( chan. subscribed, " the channel should not be subscribed " )
145
+ pusher. connect ( )
146
+
147
+ waitForExpectations ( timeout: 0.5 )
148
+ }
149
+
150
+ func testAuthorizationUsingSomethingConformingToTheAuthRequestBuilderProtocol( ) {
151
+
152
+ class AuthRequestBuilder : AuthRequestBuilderProtocol {
153
+ func requestFor( socketID: String , channel: PusherChannel ) -> NSMutableURLRequest ? {
154
+ let request = NSMutableURLRequest ( url: URL ( string: " http://localhost:9292/builder " ) !)
155
+ request. httpMethod = " POST "
117
156
request. httpBody = " socket_id= \( socketID) &channel_name= \( channel. name) " . data ( using: String . Encoding. utf8)
118
157
request. addValue ( " myToken " , forHTTPHeaderField: " Authorization " )
119
158
return request
0 commit comments