Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
asi-http-request
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Ben Copsey
2008-11-10 12:08:15 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
cfb68f81d27369d2c94a7a84a95d85a8da45af88
cfb68f81
1 parent
4ae9142e
Added tests for Basic and Digest authentication
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
123 additions
and
8 deletions
ASIFormDataRequestTests.m
ASIHTTPRequestTests.h
ASIHTTPRequestTests.m
asi-http-request.xcodeproj/project.pbxproj
ASIFormDataRequestTests.m
View file @
cfb68f8
...
...
@@ -32,5 +32,7 @@
BOOL
success
=
([[
request
dataString
]
isEqualToString
:[
NSString
stringWithFormat
:
@"post_var: %@
\r\n
file_name: %@
\r\n
file_size: %hu"
,
@"foo"
,
@"bigfile"
,
size
]]);
STAssertTrue
(
success
,
@"Failed to upload the correct data"
);
}
@end
...
...
ASIHTTPRequestTests.h
View file @
cfb68f8
...
...
@@ -21,5 +21,7 @@
-
(
void
)
testDownloadProgress
;
-
(
void
)
testUploadProgress
;
-
(
void
)
testCookies
;
-
(
void
)
testBasicAuthentication
;
-
(
void
)
testDigestAuthentication
;
@end
...
...
ASIHTTPRequestTests.m
View file @
cfb68f8
...
...
@@ -14,14 +14,6 @@
@implementation
ASIHTTPRequestTests
/*
More tests needed for:
- Delegates - success and failure
- Authentication
- Keychains
- Session persistence
*/
-
(
void
)
testBasicDownload
...
...
@@ -245,5 +237,124 @@ More tests needed for:
}
-
(
void
)
testBasicAuthentication
{
NSURL
*
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://asi/asi-http-request/tests/basic-authentication"
]
autorelease
];
ASIHTTPRequest
*
request
;
BOOL
success
;
NSError
*
err
;
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseKeychainPersistance
:
NO
];
[
request
start
];
success
=
([[[[
request
error
]
userInfo
]
objectForKey
:
@"Description"
]
isEqualToString
:
@"Your username and password were incorrect."
]);
STAssertTrue
(
success
,
@"Failed to generate permission denied error with no credentials"
);
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseKeychainPersistance
:
NO
];
[
request
setUsername
:
@"wrong"
];
[
request
setPassword
:
@"wrong"
];
[
request
start
];
success
=
([[[[
request
error
]
userInfo
]
objectForKey
:
@"Description"
]
isEqualToString
:
@"Your username and password were incorrect."
]);
STAssertTrue
(
success
,
@"Failed to generate permission denied error with wrong credentials"
);
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseSessionPersistance
:
YES
];
[
request
setUseKeychainPersistance
:
YES
];
[
request
setUsername
:
@"secret_username"
];
[
request
setPassword
:
@"secret_password"
];
[
request
start
];
err
=
[
request
error
];
STAssertNil
(
err
,
@"Failed to supply correct username and password"
);
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseSessionPersistance
:
NO
];
[
request
setUseKeychainPersistance
:
NO
];
[
request
start
];
success
=
([[[[
request
error
]
userInfo
]
objectForKey
:
@"Description"
]
isEqualToString
:
@"Your username and password were incorrect."
]);
STAssertTrue
(
success
,
@"Reused credentials when we shouldn't have"
);
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseSessionPersistance
:
YES
];
[
request
setUseKeychainPersistance
:
NO
];
[
request
start
];
err
=
[
request
error
];
STAssertNil
(
err
,
@"Failed to reuse credentials"
);
[
ASIHTTPRequest
clearSession
];
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseKeychainPersistance
:
NO
];
[
request
start
];
success
=
([[[[
request
error
]
userInfo
]
objectForKey
:
@"Description"
]
isEqualToString
:
@"Your username and password were incorrect."
]);
STAssertTrue
(
success
,
@"Failed to clear credentials"
);
//This test may show a dialog!
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseKeychainPersistance
:
YES
];
[
request
start
];
err
=
[
request
error
];
STAssertNil
(
err
,
@"Failed to use stored credentials"
);
}
-
(
void
)
testDigestAuthentication
{
[
ASIHTTPRequest
clearSession
];
NSURL
*
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://asi/asi-http-request/tests/digest-authentication"
]
autorelease
];
ASIHTTPRequest
*
request
;
BOOL
success
;
NSError
*
err
;
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseKeychainPersistance
:
NO
];
[
request
start
];
success
=
([[[[
request
error
]
userInfo
]
objectForKey
:
@"Description"
]
isEqualToString
:
@"Your username and password were incorrect."
]);
STAssertTrue
(
success
,
@"Failed to generate permission denied error with no credentials"
);
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseKeychainPersistance
:
NO
];
[
request
setUsername
:
@"wrong"
];
[
request
setPassword
:
@"wrong"
];
[
request
start
];
success
=
([[[[
request
error
]
userInfo
]
objectForKey
:
@"Description"
]
isEqualToString
:
@"Your username and password were incorrect."
]);
STAssertTrue
(
success
,
@"Failed to generate permission denied error with wrong credentials"
);
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseSessionPersistance
:
YES
];
[
request
setUseKeychainPersistance
:
YES
];
[
request
setUsername
:
@"secret_username"
];
[
request
setPassword
:
@"secret_password"
];
[
request
start
];
err
=
[
request
error
];
STAssertNil
(
err
,
@"Failed to supply correct username and password"
);
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseSessionPersistance
:
NO
];
[
request
setUseKeychainPersistance
:
NO
];
[
request
start
];
success
=
([[[[
request
error
]
userInfo
]
objectForKey
:
@"Description"
]
isEqualToString
:
@"Your username and password were incorrect."
]);
STAssertTrue
(
success
,
@"Reused credentials when we shouldn't have"
);
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseSessionPersistance
:
YES
];
[
request
setUseKeychainPersistance
:
NO
];
[
request
start
];
err
=
[
request
error
];
STAssertNil
(
err
,
@"Failed to reuse credentials"
);
[
ASIHTTPRequest
clearSession
];
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setUseKeychainPersistance
:
NO
];
[
request
start
];
success
=
([[[[
request
error
]
userInfo
]
objectForKey
:
@"Description"
]
isEqualToString
:
@"Your username and password were incorrect."
]);
STAssertTrue
(
success
,
@"Failed to clear credentials"
);
}
@end
...
...
asi-http-request.xcodeproj/project.pbxproj
View file @
cfb68f8
This diff was suppressed by a .gitattributes entry.
Please
register
or
login
to post a comment