Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #166 from n-studio/master

added credential persistence option in HTTP
  • Loading branch information...
commit 82db68ddac22dff379f1127a8d9b33f51832d09d 2 parents f84735e + 0eef70a
@supermarin supermarin authored
Showing with 14 additions and 3 deletions.
  1. +2 −1  motion/http.rb
  2. +12 −2 spec/motion/http_spec.rb
View
3  motion/http.rb
@@ -100,6 +100,7 @@ def initialize(url_string, http_method = :get, options={})
@headers = escape_line_feeds(options.delete :headers)
@format = options.delete(:format)
@cache_policy = options.delete(:cache_policy) || NSURLRequestUseProtocolCachePolicy
+ @credential_persistence = options.delete(:credential_persistence) || NSURLCredentialPersistenceForSession
@options = options
@response = HTTP::Response.new
@@ -175,7 +176,7 @@ def connectionDidFinishLoading(connection)
def connection(connection, didReceiveAuthenticationChallenge:challenge)
if (challenge.previousFailureCount == 0)
- new_credential = NSURLCredential.credentialWithUser(credentials[:username], password:credentials[:password], persistence:NSURLCredentialPersistenceForSession)
+ new_credential = NSURLCredential.credentialWithUser(credentials[:username], password:credentials[:password], persistence:@credential_persistence)
challenge.sender.useCredential(new_credential, forAuthenticationChallenge:challenge)
log "auth challenged, answered with credentials: #{credentials.inspect}"
else
View
14 spec/motion/http_spec.rb
@@ -103,6 +103,7 @@ def test_http_method(method)
before do
@credentials = { username: 'mneorr', password: '123456xx!@crazy' }
+ @credential_persistence = 0
@payload = {
user: { name: 'marin', surname: 'usalj' },
twitter: '@mneorr',
@@ -124,6 +125,7 @@ def test_http_method(method)
files: @files,
payload: @payload,
credentials: @credentials,
+ credential_persistence: @credential_persistence,
headers: @headers,
cache_policy: @cache_policy,
leftover_option: @leftover_option,
@@ -316,6 +318,14 @@ def sample_data
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
@@ -614,8 +624,8 @@ def query_received_data
@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
end
Please sign in to comment.
Something went wrong with that request. Please try again.