[vlc-commits] test/keystore: test if realm and authtype match
Thomas Guillem
git at videolan.org
Mon Jan 23 10:22:22 CET 2017
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Jan 23 10:07:43 2017 +0100| [9a682eb8028dee943718736b8491fa1551e8c935] | committer: Thomas Guillem
test/keystore: test if realm and authtype match
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9a682eb8028dee943718736b8491fa1551e8c935
---
test/src/misc/keystore.c | 86 ++++++++++++++++++++++++++++--------------------
1 file changed, 51 insertions(+), 35 deletions(-)
diff --git a/test/src/misc/keystore.c b/test/src/misc/keystore.c
index aadd763..220366f 100644
--- a/test/src/misc/keystore.c
+++ b/test/src/misc/keystore.c
@@ -42,13 +42,21 @@ struct cred
const char *psz_pwd;
};
+struct cred_res
+{
+ const char *psz_user;
+ const char *psz_pwd;
+ const char *psz_realm;
+ const char *psz_authtype;
+};
+
static const struct testcase
{
bool b_found;
const char *psz_url;
const char *psz_realm;
const char *psz_authtype;
- struct cred result;
+ struct cred_res result;
struct cred opt;
struct cred dialog;
bool b_dialog_store;
@@ -63,28 +71,28 @@ static const struct testcase
/* First tests use sftp protocol: no realm and results doesn't depend on
* path */
{ true, SFTP("user1:pwd1 at ex.com/testing/deprecated_url"),
- { "user1", "pwd1" }, {} , {}, false },
+ { "user1", "pwd1", NULL, NULL }, {} , {}, false },
{ true, SFTP("ex.com/testing/opt"),
- { "user1", "pwd1" }, { "user1", "pwd1" }, {}, false },
+ { "user1", "pwd1", NULL, NULL }, { "user1", "pwd1" }, {}, false },
{ true, SFTP("ex.com/testing/dial"),
- { "user1", "pwd1" }, {}, { "user1", "pwd1" }, false },
+ { "user1", "pwd1", NULL, NULL }, {}, { "user1", "pwd1" }, false },
WIPE_MEMORY_KEYSTORE,
{ true, SFTP("user1 at ex.com/testing/url_dial"),
- { "user1", "pwd1" }, { NULL, NULL }, { NULL, "pwd1" }, false },
+ { "user1", "pwd1", NULL, NULL }, { NULL, NULL }, { NULL, "pwd1" }, false },
WIPE_MEMORY_KEYSTORE,
{ true, SFTP("ex.com/testing/opt_dial"),
- { "user1", "pwd1" }, { "user1", NULL }, { NULL, "pwd1" }, false },
+ { "user1", "pwd1", NULL, NULL }, { "user1", NULL }, { NULL, "pwd1" }, false },
WIPE_MEMORY_KEYSTORE,
{ true, SFTP("WRONG_USER at ex.com/testing/url_opt_dial"),
- { "user1", "pwd1" }, { "user1", NULL }, { NULL, "pwd1" }, false },
+ { "user1", "pwd1", NULL, NULL }, { "user1", NULL }, { NULL, "pwd1" }, false },
WIPE_MEMORY_KEYSTORE,
@@ -92,111 +100,111 @@ static const struct testcase
* found by future tests */
{ true, SFTP("ex.com/testing/mem_ks_store"),
- { "user1", "pwd1" }, {}, { "user1", "pwd1" }, false },
+ { "user1", "pwd1", NULL, NULL }, {}, { "user1", "pwd1" }, false },
{ true, SFTP("ex.com/testing/mem_ks_find"),
- { "user1", "pwd1" }, {}, {}, false },
+ { "user1", "pwd1", NULL, NULL }, {}, {}, false },
WIPE_MEMORY_KEYSTORE,
{ false, SFTP("ex.com/testing/mem_ks_find"),
- { "user1", "pwd1" }, {}, {}, false },
+ { "user1", "pwd1", NULL, NULL }, {}, {}, false },
WIPE_MEMORY_KEYSTORE,
/* Testing permanent keystore */
{ true, SFTP("ex.com/testing/ks_store"),
- { "user1", "pwd1" }, {}, { "user1", "pwd1" }, true },
+ { "user1", "pwd1", NULL, NULL }, {}, { "user1", "pwd1" }, true },
WIPE_MEMORY_KEYSTORE,
{ true, SFTP("ex.com/testing/ks_find"),
- { "user1", "pwd1" }, {}, {}, false },
+ { "user1", "pwd1", NULL, NULL }, {}, {}, false },
{ true, SFTP("ex.com:2022/testing/ks_store"),
- { "user2", "pwd2" }, {}, { "user2", "pwd2" }, true },
+ { "user2", "pwd2", NULL, NULL }, {}, { "user2", "pwd2" }, true },
WIPE_MEMORY_KEYSTORE,
{ true, SFTP("user1 at ex.com/testing/ks_find"),
- { "user1", "pwd1" }, {}, {}, false },
+ { "user1", "pwd1", NULL, NULL }, {}, {}, false },
{ true, SFTP("user2 at ex.com:2022/testing/ks_find"),
- { "user2", "pwd2" }, {}, {}, false },
+ { "user2", "pwd2", NULL, NULL }, {}, {}, false },
{ false, SFTP("user2 at wrong_host.com:2022/testing/ks_find"),
- { "user2", "pwd2" }, {}, {}, false },
+ { "user2", "pwd2", NULL, NULL }, {}, {}, false },
{ false, SFTP("user2 at ex.com/testing/ks_find"),
- { "user2", "pwd2" }, {}, {}, false },
+ { "user2", "pwd2", NULL, NULL }, {}, {}, false },
{ false, SMB("user2 at ex.com:2022/testing/ks_find"),
- { "user2", "pwd2" }, {}, {}, false },
+ { "user2", "pwd2", NULL, NULL }, {}, {}, false },
WIPE_MEMORY_KEYSTORE,
{ true, SFTP("ex.com/testing/opt_not_storing_ks"),
- { "user3", "pwd3" }, { "user3", "pwd3" }, {}, true },
+ { "user3", "pwd3", NULL, NULL }, { "user3", "pwd3" }, {}, true },
WIPE_MEMORY_KEYSTORE,
{ false, SFTP("ex.com/testing/opt_not_storing_ks"),
- { "user3", "pwd3" }, {}, {}, false },
+ { "user3", "pwd3", NULL, NULL }, {}, {}, false },
WIPE_MEMORY_KEYSTORE,
/* Testing reusing http credentials rfc7617#2.2 */
{ true, HTTP("ex.com/testing/good_path/ks_store_realm", "Realm"),
- { "user4", "pwd4" }, {}, { "user4", "pwd4" }, true },
+ { "user4", "pwd4", "Realm", "Basic" }, {}, { "user4", "pwd4" }, true },
{ false, HTTP("ex.com/testing/good_path/ks_find_realm", "Wrong realm"),
- { "user4", "pwd4" }, {}, {}, false },
+ { "user4", "pwd4", "Wrong realm", "Basic" }, {}, {}, false },
{ true, HTTP("ex.com/testing/good_path/ks_find_realm", "Realm"),
- { "user4", "pwd4" }, {}, {}, false },
+ { "user4", "pwd4", "Realm", "Basic" }, {}, {}, false },
{ true, HTTP("ex.com/testing/good_path/another_path/ks_find_realm", "Realm"),
- { "user4", "pwd4" }, {}, {}, false },
+ { "user4", "pwd4", "Realm", "Basic" }, {}, {}, false },
{ false, HTTP("ex.com/testing/wrong_path/ks_find_realm", "Realm"),
- { "user4", "pwd4" }, {}, {}, false },
+ { "user4", "pwd4", "Realm", "Basic" }, {}, {}, false },
/* Testing reusing smb credentials */
{ true, SMB("host/share/path1/path2/path3/ks_store"),
- { "user5", "pwd5" }, {}, { "user5", "pwd5" }, false },
+ { "user5", "pwd5", NULL, NULL }, {}, { "user5", "pwd5" }, false },
{ true, SMB("host/share/path4/ks_find"),
- { "user5", "pwd5" }, {}, {}, false },
+ { "user5", "pwd5", NULL, NULL }, {}, {}, false },
{ false, SMB("wrong_host/share/path4/ks_find"),
- { "user5", "pwd5" }, {}, {}, false },
+ { "user5", "pwd5", NULL, NULL }, {}, {}, false },
{ false, SMB("host/wrong_share/path4/ks_find"),
- { "user5", "pwd5" }, {}, {}, false },
+ { "user5", "pwd5", NULL, NULL }, {}, {}, false },
WIPE_MEMORY_KEYSTORE,
/* Testing smb realm split */
{ true, SMB("host/share/path1/ks_store"),
- { "user6", "pwd6" }, {}, { "domain;user6", "pwd6" }, false },
+ { "user6", "pwd6", "domain", NULL }, {}, { "domain;user6", "pwd6" }, false },
{ true, SMB("domain;user6 at host/share/path1/ks_find"),
- { "user6", "pwd6" }, {}, {}, false },
+ { "user6", "pwd6", "domain", NULL }, {}, {}, false },
{ false, SMB("wrong_domain;user6 at host/share/path1/ks_find"),
- { "user6", "pwd6" }, {}, {}, false },
+ { "user6", "pwd6", "wrong_domain", NULL }, {}, {}, false },
WIPE_MEMORY_KEYSTORE,
{ false, "://invalid_url", NULL, NULL,
- { "user1", "pwd1" }, {}, { "user1", "pwd1" }, false },
+ { "user1", "pwd1", NULL, NULL }, {}, { "user1", "pwd1" }, false },
{ false, "/invalid_path", NULL, NULL,
- { "user1", "pwd1" }, {}, { "user1", "pwd1" }, false },
+ { "user1", "pwd1", NULL, NULL }, {}, { "user1", "pwd1" }, false },
};
struct dialog_ctx
@@ -281,7 +289,15 @@ test(vlc_object_t *p_obj, unsigned int i_id, const struct testcase *p_test)
while (vlc_credential_get(&credential, p_obj, psz_opt_user, psz_opt_pwd,
"test authentication", "this a test"))
{
- if (strcmp(credential.psz_username, p_test->result.psz_user) == 0
+ bool realm_match = !p_test->result.psz_realm
+ || (credential.psz_realm
+ && strcmp(credential.psz_realm, p_test->result.psz_realm) == 0);
+ bool authtype_match = !p_test->result.psz_authtype
+ || (credential.psz_authtype
+ && strcmp(credential.psz_authtype, p_test->result.psz_authtype) == 0);
+
+ if (realm_match && authtype_match
+ && strcmp(credential.psz_username, p_test->result.psz_user) == 0
&& strcmp(credential.psz_password, p_test->result.psz_pwd) == 0)
{
b_found = true;
More information about the vlc-commits
mailing list