~ubuntu-branches/ubuntu/saucy/curl/saucy-201307251546

« back to all changes in this revision

Viewing changes to tests/unit/unit1304.c

  • Committer: Bazaar Package Importer
  • Author(s): Ramakrishnan Muthukrishnan
  • Date: 2011-02-28 19:35:36 UTC
  • mto: (3.6.1 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: james.westby@ubuntu.com-20110228193536-p3a9jawxxofcsz7o
Tags: upstream-7.21.4
ImportĀ upstreamĀ versionĀ 7.21.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include "curl_config.h"
 
3
#include "setup.h"
 
4
 
 
5
#include "netrc.h"
 
6
#include "curlcheck.h"
 
7
 
 
8
char login[LOGINSIZE];
 
9
char password[PASSWORDSIZE];
 
10
char filename[64];
 
11
 
 
12
static CURLcode unit_setup(void)
 
13
{
 
14
  password[0] = 0;
 
15
  login[0] = 0;
 
16
  return CURLE_OK;
 
17
}
 
18
 
 
19
static void unit_stop(void)
 
20
{
 
21
}
 
22
 
 
23
UNITTEST_START
 
24
  int result;
 
25
 
 
26
  static const char* filename1 = "log/netrc";
 
27
  memcpy(filename, filename1, strlen(filename1));
 
28
 
 
29
  /*
 
30
   * Test a non existent host in our netrc file.
 
31
   */
 
32
  result = Curl_parsenetrc("test.example.com", login, password, filename);
 
33
  fail_unless(result == 1, "Host not found should return 1");
 
34
  fail_unless(password[0] == 0, "password should not have been changed");
 
35
  fail_unless(login[0] == 0, "login should not have been changed");
 
36
 
 
37
  /*
 
38
   * Test a non existent login in our netrc file.
 
39
   */
 
40
  memcpy(login, "me", 2);
 
41
  result = Curl_parsenetrc("example.com", login, password, filename);
 
42
  fail_unless(result == 0, "Host should be found");
 
43
  fail_unless(password[0] == 0, "password should not have been changed");
 
44
  fail_unless(strncmp(login, "me", 2) == 0, "login should not have been changed");
 
45
 
 
46
  /*
 
47
   * Test a non existent login and host in our netrc file.
 
48
   */
 
49
  memcpy(login, "me", 2);
 
50
  result = Curl_parsenetrc("test.example.com", login, password, filename);
 
51
  fail_unless(result == 1, "Host should be found");
 
52
  fail_unless(password[0] == 0, "password should not have been changed");
 
53
  fail_unless(strncmp(login, "me", 2) == 0, "login should not have been changed");
 
54
 
 
55
  /*
 
56
   * Test a non existent login (substring of an existing one) in our
 
57
   * netrc file.
 
58
   */
 
59
  memcpy(login, "admi", 4);
 
60
  result = Curl_parsenetrc("example.com", login, password, filename);
 
61
  fail_unless(result == 0, "Host should be found");
 
62
  fail_unless(password[0] == 0, "password should not have been changed");
 
63
  fail_unless(strncmp(login, "admi", 4) == 0, "login should not have been changed");
 
64
 
 
65
  /*
 
66
   * Test a non existent login (superstring of an existing one)
 
67
   * in our netrc file.
 
68
   */
 
69
  memcpy(login, "adminn", 6);
 
70
  result = Curl_parsenetrc("example.com", login, password, filename);
 
71
  fail_unless(result == 0, "Host should be found");
 
72
  fail_unless(password[0] == 0, "password should not have been changed");
 
73
  fail_unless(strncmp(login, "adminn", 6) == 0, "login should not have been changed");
 
74
 
 
75
  /*
 
76
   * Test for the first existing host in our netrc file
 
77
   * with login[0] = 0.
 
78
   */
 
79
  login[0] = 0;
 
80
  result = Curl_parsenetrc("example.com", login, password, filename);
 
81
  fail_unless(result == 0, "Host should have been found");
 
82
  fail_unless(strncmp(password, "passwd", 6) == 0,
 
83
              "password should be 'passwd'");
 
84
  fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
 
85
 
 
86
  /*
 
87
   * Test for the first existing host in our netrc file
 
88
   * with login[0] != 0.
 
89
   */
 
90
  password[0] = 0;
 
91
  result = Curl_parsenetrc("example.com", login, password, filename);
 
92
  fail_unless(result == 0, "Host should have been found");
 
93
  fail_unless(strncmp(password, "passwd", 6) == 0,
 
94
              "password should be 'passwd'");
 
95
  fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
 
96
 
 
97
  /*
 
98
   * Test for the second existing host in our netrc file
 
99
   * with login[0] = 0.
 
100
   */
 
101
  password[0] = 0;
 
102
  login[0] = 0;
 
103
  result = Curl_parsenetrc("curl.example.com", login, password, filename);
 
104
  fail_unless(result == 0, "Host should have been found");
 
105
  fail_unless(strncmp(password, "none", 4) == 0,
 
106
              "password should be 'none'");
 
107
  fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
 
108
 
 
109
  /*
 
110
   * Test for the second existing host in our netrc file
 
111
   * with login[0] != 0.
 
112
   */
 
113
  password[0] = 0;
 
114
  result = Curl_parsenetrc("curl.example.com", login, password, filename);
 
115
  fail_unless(result == 0, "Host should have been found");
 
116
  fail_unless(strncmp(password, "none", 4) == 0,
 
117
              "password should be 'none'");
 
118
  fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
 
119
 
 
120
  /* TODO:
 
121
   * Test over the size limit password / login!
 
122
   * Test files with a bad format
 
123
   */
 
124
UNITTEST_STOP