spec/motion/http_spec.rb in bubble-wrap-1.1.4 vs spec/motion/http_spec.rb in bubble-wrap-1.1.5
- old
+ new
@@ -101,10 +101,11 @@
describe "HTTP::Query" do
before do
@credentials = { username: 'mneorr', password: '123456xx!@crazy' }
+ @credential_persistence = 0
@payload = {
user: { name: 'marin', surname: 'usalj' },
twitter: '@mneorr',
website: 'mneorr.com',
values: ['apple', 'orange', 'peach'],
@@ -122,10 +123,11 @@
@options = {
action: @action,
files: @files,
payload: @payload,
credentials: @credentials,
+ credential_persistence: @credential_persistence,
headers: @headers,
cache_policy: @cache_policy,
leftover_option: @leftover_option,
format: @format
}
@@ -314,10 +316,18 @@
new_query = BubbleWrap::HTTP::Query.new( @localhost_url, :get, {})
new_query.instance_variable_get(:@cache_policy).should.equal NSURLRequestUseProtocolCachePolicy
end
+ it "should delete :credential_persistence or set NSURLCredentialPersistenceForSession" do
+ @query.instance_variable_get(:@credential_persistence).should.equal @credential_persistence
+ @options.should.not.has_key? :credential_persistence
+
+ new_query = BubbleWrap::HTTP::Query.new( @localhost_url, :get, {})
+ new_query.instance_variable_get(:@credential_persistence).should.equal NSURLCredentialPersistenceForSession
+ end
+
it "should set the rest of options{} to ivar @options" do
@query.options.size.should.equal 1
@query.options.values[0].should.equal @leftover_option
end
@@ -612,23 +622,48 @@
@challenge.sender.challenge.should.equal @challenge
@challenge.sender.credential.user.should.equal @credentials[:username]
@challenge.sender.credential.password.should.equal @credentials[:password]
end
- it "always uses NSURLCredentialPersistenceForSession" do
- @challenge.sender.credential.persistence.should.equal NSURLCredentialPersistenceForSession
+ it "should use Credential Persistence set in options" do
+ @challenge.sender.credential.persistence.should.equal @credential_persistence
end
+ it 'should continue without credentials when no credentials provided' do
+ @options.delete :credentials
+ @query = BubbleWrap::HTTP::Query.new( @localhost_url , :get, @options )
+ @query.connection(nil, didReceiveAuthenticationChallenge:@challenge)
+ @challenge.sender.continue_without_credential.should.equal true
+ end
+
end
+ describe "properly format payload to url get query string" do
+
+ before do
+ @payload = {"we love" => '#==Rock&Roll==#', "radio" => "Ga Ga", "qual" => 3.0, "incr" => -1}
+ @url_string = 'http://fake.url/method'
+ @get_query = BubbleWrap::HTTP::Query.new( @url_string, :get, :payload => @payload)
+ @escaped_url = "http://fake.url/method?we%20love=%23%3D%3DRock%26Roll%3D%3D%23&radio=Ga%20Ga&qual=3.0&incr=-1"
+ end
+
+ it "should escape \#=& characters only in keys and values" do
+ @get_query.instance_variable_get(:@url).description.should.equal @escaped_url
+ end
+
+ end
+
class FakeSender
- attr_reader :challenge, :credential, :was_cancelled
+ attr_reader :challenge, :credential, :was_cancelled, :continue_without_credential
def cancelAuthenticationChallenge(challenge)
@was_cancelled = true
end
def useCredential(credential, forAuthenticationChallenge:challenge)
@challenge = challenge
@credential = credential
+ end
+ def continueWithoutCredentialForAuthenticationChallenge(challenge)
+ @continue_without_credential = true
end
end
class FakeChallenge
attr_accessor :previousFailureCount