8 #include <CUnit/CUnit.h>
9 #include "wget_agent.h"
28 int pid = system(
"echo 'hello world' > ./test.file");
29 if (WIFEXITED(pid)) pid = WEXITSTATUS(pid);
31 char Fname[] =
"./test.file";
32 int isFile =
IsFile(Fname, 1);
33 CU_ASSERT_EQUAL(isFile, 1);
47 int pid = system(
"echo 'hello world' > ./test.file");
48 if (WIFEXITED(pid)) pid = WEXITSTATUS(pid);
50 char Fname[] =
"./test.file";
51 int isFile =
IsFile(Fname, 0);
52 CU_ASSERT_EQUAL(isFile, 1);
53 char NewFname[] =
"./link.file";
54 pid = symlink(Fname, NewFname);
55 isFile =
IsFile(NewFname, 1);
56 CU_ASSERT_EQUAL(isFile, 1);
73 strcpy(URL,
"http://fossology.org");
75 CU_ASSERT_EQUAL(pos, 7);
76 memset(URL, 0, MAX_LENGTH);
77 strcpy(URL,
"https://encrypted.google.com/");
79 CU_ASSERT_EQUAL(pos, 8);
80 memset(URL, 0, MAX_LENGTH);
81 strcpy(URL,
"ftp://osms.chn.hp.com/pub/fossology/");
83 CU_ASSERT_EQUAL(pos, 6);
96 char Sout[MAX_LENGTH];
97 int SoutSize = MAX_LENGTH;
99 strcpy(Sin,
"http://fossology.org #");
100 int result =
TaintURL(Sin, Sout, SoutSize);
101 CU_ASSERT_EQUAL(result, 0);
103 strcpy(Sin,
"http://fossology.org/`debian/ 1.0.0/");
104 result =
TaintURL(Sin, Sout, SoutSize);
105 CU_ASSERT_EQUAL(result, 1);
120 char source_path[] =
"/srv/fossology/testDbRepo12704556/%H/wget";
121 char des_path[1024] = {0};
122 char HostName[1024] = {0};
123 char *taint_path =
PathCheck(source_path);
124 gethostname(HostName,
sizeof(HostName));
125 snprintf(des_path,
sizeof(des_path),
"/srv/fossology/testDbRepo12704556/%s/wget", HostName);
126 CU_ASSERT_STRING_EQUAL(des_path, taint_path);
139 char file_path[] =
"./";
140 char tar_file[] =
"/tmp/Suckupfs.tar.dir/test.tar";
141 char des_dir[] =
"/tmp/Suckupfs.tar.dir/";
143 char commands[1024] =
"";
145 if (stat(file_path, &Status) != 0)
return;
147 int res =
Archivefs(file_path, tar_file, des_dir, Status);
148 CU_ASSERT_EQUAL(1, res);
149 tar_status = stat(file_path, &Status);
150 CU_ASSERT_EQUAL(0, tar_status);
151 snprintf(commands,
sizeof(commands),
"file %s |grep 'tar archive' >/dev/null 2>&1", tar_file);
152 int rc = system(commands);
153 CU_ASSERT_EQUAL(1, rc != -1 && (WEXITSTATUS(rc) == 0));
166 char file_path[] =
"./Makefile";
167 char tar_file[] =
"/tmp/Suckupfs.tar.dir/testfile";
168 char des_dir[] =
"/tmp/Suckupfs.tar.dir/";
170 char commands[1024] =
"";
172 if (stat(file_path, &Status) != 0)
return;
174 int res =
Archivefs(file_path, tar_file, des_dir, Status);
175 CU_ASSERT_EQUAL(1, res);
176 tar_status = stat(file_path, &Status);
177 CU_ASSERT_EQUAL(0, tar_status);
178 snprintf(commands,
sizeof(commands),
"file %s |grep ASCII >/dev/null 2>&1", tar_file);
179 int rc = system(commands);
180 CU_ASSERT_EQUAL(1, rc != -1 && (WEXITSTATUS(rc) == 0));
void test_Archivefs_dir()
Test for function Archivefs(), dir.
void test_Archivefs_file()
Test for function Archivefs(), reguler file.
void testIsFileNormal_SymLink()
Test for function IsFile() a symlink.
void testIsFileNormal_RegulerFile()
Test for function IsFile()
CU_TestInfo testcases_Utiliies[]
testcases for function SetEnv
void testGetPositionNormal()
Test for function GetPosition()
void test_PathCheck()
Test for function PathCheck()
void testTaintURL()
Test for function TaintURL()
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
char * PathCheck(char *DirPath)
Check if path contains a "%U" or "%H". If so, substitute a unique ID for U.
int IsFile(long mode)
Check if the pfile_id is a file.
int GetPosition(char *URL)
Get the position (ending + 1) of http|https|ftp:// of one url.
int TaintURL(char *Sin, char *Sout, int SoutSize)
Given a URL string, taint-protect it.
int Archivefs(char *Path, char *TempFile, char *TempFileDir, struct stat Status)
Copy downloaded files to temporary directory.