Skip to content

Commit 6f5a131

Browse files
committed
Add test for parse_user_name
Signed-off-by: Simo Sorce <[email protected]>
1 parent 9266d37 commit 6f5a131

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

tests/ntlmssptest.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,6 +2702,92 @@ int test_ACQ_NO_NAME(void)
27022702
return ret;
27032703
}
27042704

2705+
int test_import_name(void)
2706+
{
2707+
struct {
2708+
const char *name;
2709+
const char *username;
2710+
const char *domain;
2711+
uint32_t error;
2712+
} name_test[] = {
2713+
{ "foo", "foo", NULL, 0 },
2714+
{ "BAR\\foo", "foo", "BAR", 0 },
2715+
{ "foo@BAR", "foo", "BAR", 0 },
2716+
{ "foo\\@bar.baz", "[email protected]", NULL, 0 },
2717+
{ "foo\\@bar.baz@BAR", "[email protected]", "BAR", 0 },
2718+
2719+
{ "BAR\\[email protected]", "[email protected]", "BAR", 0 },
2720+
{ "BAR@baz\\[email protected]", "[email protected]", "BAR@baz", 0 },
2721+
{ "BAR@baz\\@[email protected]", NULL, NULL, GSS_S_FAILURE },
2722+
{ "BAR\\foo\\@bar.baz", NULL, NULL, GSS_S_FAILURE },
2723+
{ "foo@bar\\@baz", NULL, NULL, GSS_S_FAILURE },
2724+
{ NULL, NULL, NULL, 0 }
2725+
};
2726+
int ret = 0;
2727+
2728+
for (int i = 0; name_test[i].name != NULL; i++) {
2729+
struct gssntlm_name *gss_username = NULL;
2730+
gss_buffer_desc username;
2731+
uint32_t retmin, retmaj;
2732+
bool failed = false;
2733+
2734+
username.value = discard_const(name_test[i].name);
2735+
username.length = strlen(username.value);
2736+
2737+
retmaj = gssntlm_import_name(&retmin, &username,
2738+
GSS_C_NT_USER_NAME,
2739+
(gss_name_t *)&gss_username);
2740+
if (retmaj != name_test[i].error) {
2741+
failed = true;
2742+
} else if (retmaj == GSS_S_COMPLETE) {
2743+
if ((gss_username->data.user.name == NULL &&
2744+
name_test[i].username != NULL) ||
2745+
(name_test[i].username == NULL &&
2746+
gss_username->data.user.name != NULL) ||
2747+
(gss_username->data.user.name != NULL &&
2748+
name_test[i].username != NULL &&
2749+
strcmp(gss_username->data.user.name,
2750+
name_test[i].username) != 0)) {
2751+
failed = true;
2752+
}
2753+
if ((gss_username->data.user.domain == NULL &&
2754+
name_test[i].domain != NULL) ||
2755+
(name_test[i].domain == NULL &&
2756+
gss_username->data.user.domain != NULL) ||
2757+
(gss_username->data.user.domain != NULL &&
2758+
name_test[i].domain != NULL &&
2759+
strcmp(gss_username->data.user.domain,
2760+
name_test[i].domain) != 0)) {
2761+
failed = true;
2762+
}
2763+
}
2764+
2765+
if (failed) {
2766+
fprintf(stderr, "gssntlm_import_name(%s) failed!\n",
2767+
name_test[i].name);
2768+
fprintf(stderr, "Expected: [%s]\\[%s]\n",
2769+
name_test[i].domain, name_test[i].username);
2770+
if (gss_username) {
2771+
fprintf(stderr, "Obtained: [%s]\\[%s]\n",
2772+
gss_username->data.user.domain,
2773+
gss_username->data.user.name);
2774+
}
2775+
if (retmaj) {
2776+
print_gss_error("Function returned error.", retmaj, retmin);
2777+
} else {
2778+
fprintf(stderr, "Expected error: %d", (int)name_test[i].error);
2779+
fflush(stderr);
2780+
}
2781+
2782+
ret++;
2783+
}
2784+
2785+
gssntlm_release_name(&retmin, (gss_name_t *)&gss_username);
2786+
}
2787+
2788+
return ret;
2789+
}
2790+
27052791
int main(int argc, const char *argv[])
27062792
{
27072793
struct ntlm_ctx *ctx;
@@ -2940,6 +3026,11 @@ int main(int argc, const char *argv[])
29403026
fprintf(stderr, "Test: %s\n", (ret ? "FAIL":"SUCCESS"));
29413027
if (ret) gret++;
29423028

3029+
fprintf(stderr, "Test importing different name forms\n");
3030+
ret = test_import_name();
3031+
fprintf(stderr, "Test: %s\n", (ret ? "FAIL":"SUCCESS"));
3032+
if (ret) gret += ret;
3033+
29433034
done:
29443035
ntlm_free_ctx(&ctx);
29453036
return gret;

0 commit comments

Comments
 (0)