Skip to content

Commit

Permalink
RSA8f1 (#348)
Browse files Browse the repository at this point in the history
* RSA8f1

* RSA8f1: pending

* Fix RSA8f1

* RSA8f3: misplaced
  • Loading branch information
ricardopereira authored and tcard committed May 16, 2016
1 parent 2d516fc commit 4b26dbf
Showing 1 changed file with 61 additions and 30 deletions.
91 changes: 61 additions & 30 deletions Spec/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,36 @@ class Auth : QuickSpec {

}

// RSA8f1
it("ensure the message published does not have a clientId") {
let options = AblyTests.commonAppSetup()
options.token = getTestToken(clientId: nil)
let rest = ARTRest(options: options)
rest.httpExecutor = mockExecutor
let channel = rest.channels.get("test")

waitUntil(timeout: testTimeout) { done in
let message = ARTMessage(name: nil, data: "message without an explicit clientId")
expect(message.clientId).to(beNil())
channel.publish([message]) { error in
expect(error).to(beNil())
switch extractBodyAsMessages(mockExecutor.requests.first) {
case .Failure(let error):
fail(error)
case .Success(let httpBody):
expect(httpBody.unbox.first!["clientId"]).to(beNil())
}
channel.history { page, error in
expect(error).to(beNil())
expect(page!.items).to(haveCount(1))
expect((page!.items[0] as! ARTMessage).clientId).to(beNil())
done()
}
}
}
expect(rest.auth.clientId).to(beNil())
}

// RSA8f2
it("ensure that the message is rejected") {
let options = AblyTests.commonAppSetup()
Expand All @@ -893,59 +923,60 @@ class Auth : QuickSpec {
expect(rest.auth.clientId).to(beNil())
}

// RSA8f4
it("ensure the message published with a wildcard '*' has the provided clientId") {
// RSA8f3
it("ensure the message published with a wildcard '*' does not have a clientId") {
let options = AblyTests.commonAppSetup()
// Request a token with a wildcard '*' value clientId
options.token = getTestToken(clientId: "*")
let rest = ARTRest(options: options)
rest.httpExecutor = mockExecutor
let channel = rest.channels.get("test")

waitUntil(timeout: testTimeout) { done in
let message = ARTMessage(name: nil, data: "message with an explicit clientId", clientId: "john")
let message = ARTMessage(name: nil, data: "no client")
expect(message.clientId).to(beNil())
channel.publish([message]) { error in
expect(error).to(beNil())
switch extractBodyAsMessages(mockExecutor.requests.first) {
case .Failure(let error):
fail(error)
case .Success(let httpBody):
expect(httpBody.unbox.first!["clientId"]).to(beNil())
}
channel.history { page, error in
expect(error).to(beNil())
expect(page!.items[0].clientId).to(equal("john"))
expect(page!.items).to(haveCount(1))
expect((page!.items[0] as! ARTMessage).clientId).to(beNil())
done()
}
}
}
expect(rest.auth.clientId).to(beNil())
}

}
// RSA8f4
it("ensure the message published with a wildcard '*' has the provided clientId") {
let options = AblyTests.commonAppSetup()
// Request a token with a wildcard '*' value clientId
options.token = getTestToken(clientId: "*")
let rest = ARTRest(options: options)
let channel = rest.channels.get("test")

// RSA8f3
it("ensure the message published with a wildcard '*' does not have a clientId") {
let options = AblyTests.commonAppSetup()
// Request a token with a wildcard '*' value clientId
options.token = getTestToken(clientId: "*")
let rest = ARTRest(options: options)
rest.httpExecutor = mockExecutor
let channel = rest.channels.get("test")

waitUntil(timeout: testTimeout) { done in
let message = ARTMessage(name: nil, data: "no client")
expect(message.clientId).to(beNil())
channel.publish([message]) { error in
expect(error).to(beNil())
switch extractBodyAsMessages(mockExecutor.requests.first) {
case .Failure(let error):
fail(error)
case .Success(let httpBody):
expect(httpBody.unbox.first!["clientId"]).to(beNil())
}
channel.history { page, error in
waitUntil(timeout: testTimeout) { done in
let message = ARTMessage(name: nil, data: "message with an explicit clientId", clientId: "john")
channel.publish([message]) { error in
expect(error).to(beNil())
expect(page!.items).to(haveCount(1))
expect((page!.items[0] as! ARTMessage).clientId).to(beNil())
done()
channel.history { page, error in
expect(error).to(beNil())
let item = page!.items[0] as! ARTMessage
expect(item.clientId).to(equal("john"))
done()
}
}
}
expect(rest.auth.clientId).to(beNil())
}
expect(rest.auth.clientId).to(beNil())

}

struct ExpectedTokenParams {
Expand Down

0 comments on commit 4b26dbf

Please sign in to comment.