19 #include <CUnit/CUnit.h> 20 #include "wget_agent.h" 39 int pid = system(
"echo 'hello world' > ./test.file");
40 if (WIFEXITED(pid)) pid = WEXITSTATUS(pid);
42 char Fname[] =
"./test.file";
43 int isFile =
IsFile(Fname, 1);
44 CU_ASSERT_EQUAL(isFile, 1);
58 int pid = system(
"echo 'hello world' > ./test.file");
59 if (WIFEXITED(pid)) pid = WEXITSTATUS(pid);
61 char Fname[] =
"./test.file";
62 int isFile =
IsFile(Fname, 0);
63 CU_ASSERT_EQUAL(isFile, 1);
64 char NewFname[] =
"./link.file";
65 pid = symlink(Fname, NewFname);
66 isFile =
IsFile(NewFname, 1);
67 CU_ASSERT_EQUAL(isFile, 1);
84 strcpy(URL,
"http://fossology.org");
86 CU_ASSERT_EQUAL(pos, 7);
87 memset(URL, 0, MAX_LENGTH);
88 strcpy(URL,
"https://encrypted.google.com/");
90 CU_ASSERT_EQUAL(pos, 8);
91 memset(URL, 0, MAX_LENGTH);
92 strcpy(URL,
"ftp://osms.chn.hp.com/pub/fossology/");
94 CU_ASSERT_EQUAL(pos, 6);
106 char Sin[MAX_LENGTH];
107 char Sout[MAX_LENGTH];
108 int SoutSize = MAX_LENGTH;
110 strcpy(Sin,
"http://fossology.org #");
111 int result =
TaintURL(Sin, Sout, SoutSize);
112 CU_ASSERT_EQUAL(result, 0);
114 strcpy(Sin,
"http://fossology.org/`debian/ 1.0.0/");
115 result =
TaintURL(Sin, Sout, SoutSize);
116 CU_ASSERT_EQUAL(result, 1);
131 char source_path[] =
"/srv/fossology/testDbRepo12704556/%H/wget";
132 char des_path[1024] = {0};
133 char HostName[1024] = {0};
134 char *taint_path =
PathCheck(source_path);
135 gethostname(HostName,
sizeof(HostName));
136 snprintf(des_path,
sizeof(des_path),
"/srv/fossology/testDbRepo12704556/%s/wget", HostName);
137 CU_ASSERT_STRING_EQUAL(des_path, taint_path);
150 char file_path[] =
"./";
151 char tar_file[] =
"/tmp/Suckupfs.tar.dir/test.tar";
152 char des_dir[] =
"/tmp/Suckupfs.tar.dir/";
154 char commands[1024] =
"";
156 if (stat(file_path, &Status) != 0)
return;
158 int res =
Archivefs(file_path, tar_file, des_dir, Status);
159 CU_ASSERT_EQUAL(1, res);
160 tar_status = stat(file_path, &Status);
161 CU_ASSERT_EQUAL(0, tar_status);
162 snprintf(commands,
sizeof(commands),
"file %s |grep 'tar archive' >/dev/null 2>&1", tar_file);
163 int rc = system(commands);
164 CU_ASSERT_EQUAL(1, rc != -1 && (WEXITSTATUS(rc) == 0));
177 char file_path[] =
"./Makefile";
178 char tar_file[] =
"/tmp/Suckupfs.tar.dir/testfile";
179 char des_dir[] =
"/tmp/Suckupfs.tar.dir/";
181 char commands[1024] =
"";
183 if (stat(file_path, &Status) != 0)
return;
185 int res =
Archivefs(file_path, tar_file, des_dir, Status);
186 CU_ASSERT_EQUAL(1, res);
187 tar_status = stat(file_path, &Status);
188 CU_ASSERT_EQUAL(0, tar_status);
189 snprintf(commands,
sizeof(commands),
"file %s |grep ASCII >/dev/null 2>&1", tar_file);
190 int rc = system(commands);
191 CU_ASSERT_EQUAL(1, rc != -1 && (WEXITSTATUS(rc) == 0));
char * PathCheck(char *DirPath)
Check if path contains a "%U" or "%H". If so, substitute a unique ID for U.
int Archivefs(char *Path, char *TempFile, char *TempFileDir, struct stat Status)
Copy downloaded files to temporary directory.
int GetPosition(char *URL)
Get the position (ending + 1) of http|https|ftp:// of one url.
void testIsFileNormal_RegulerFile()
Test for function IsFile()
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
int IsFile(long mode)
Check if the pfile_id is a file.
void testTaintURL()
Test for function TaintURL()
void testIsFileNormal_SymLink()
Test for function IsFile() a symlink.
void test_PathCheck()
Test for function PathCheck()
CU_TestInfo testcases_Utiliies[]
testcases for function SetEnv
void test_Archivefs_file()
Test for function Archivefs(), reguler file.
void testGetPositionNormal()
Test for function GetPosition()
int TaintURL(char *Sin, char *Sout, int SoutSize)
Given a URL string, taint-protect it.
void test_Archivefs_dir()
Test for function Archivefs(), dir.