Skip to content

Commit 3779afa

Browse files
spcaipers-armthorstendb-ARMedriouk
authored
[packchk] Validate <url> starts with https:// #1109 (#1139) (#1961)
* [packchk] Validate <url> starts with https:// #1109 --------- Co-authored-by: Thorsten de Buhr <[email protected]> Co-authored-by: Evgueni Driouk <[email protected]>
1 parent 331b229 commit 3779afa

File tree

5 files changed

+126
-2
lines changed

5 files changed

+126
-2
lines changed

tools/packchk/include/CheckFiles.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CheckFiles {
3030
void SetPackagePath(const std::string& packagePath);
3131
const std::string& GetPackagePath() const;
3232
bool CheckFile(RteItem* item);
33+
bool CheckUrls(RteItem* item);
3334
bool CheckFileExists(const std::string& fileName, int lineNo, bool associated = false);
3435
bool CheckCaseSense(const std::string& fileName, int lineNo);
3536
bool CheckFileIsInPack(const std::string& fileName, int lineNo);

tools/packchk/src/CheckFiles.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ CheckFilesVisitor::~CheckFilesVisitor()
4040
VISIT_RESULT CheckFilesVisitor::Visit(RteItem* item)
4141
{
4242
m_checkFiles.CheckFile(item);
43+
m_checkFiles.CheckUrls(item);
4344

4445
return VISIT_RESULT::CONTINUE_VISIT;
4546
}
@@ -170,6 +171,36 @@ bool CheckFiles::ToUpper(string& text)
170171
return true;
171172
}
172173

174+
/**
175+
* @brief check aspects of an RTE url item
176+
* @param item RteItem item to check
177+
* @return passed / failed
178+
*/
179+
bool CheckFiles::CheckUrls(RteItem* item)
180+
{
181+
if(!item || item->GetTag() == "package") {
182+
return true;
183+
}
184+
185+
bool bOk = true;
186+
const auto lineNo = item->GetLineNumber();
187+
188+
if(item->GetText().find("http://", 0) != string::npos) {
189+
LogMsg("M300", TAG(item->GetTag()), URL("https://"), lineNo);
190+
bOk = false;
191+
}
192+
193+
const auto& attributes = item->GetAttributes();
194+
for(const auto& [attr, text] : attributes) {
195+
if(text.find("http://", 0) != string::npos) {
196+
LogMsg("M300", TAG(attr), URL("https://"), lineNo);
197+
bOk = false;
198+
}
199+
}
200+
201+
return bOk;
202+
}
203+
173204
/**
174205
* @brief check aspects of an RTE file item
175206
* @param item RteItem item to check

tools/packchk/src/PackChk_Msgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const MsgTable PackChk::msgTable = {
105105
{ "M219", { MsgLevel::LEVEL_ERROR, CRLF_B, "Unable to find specified schema file '%PATH%'"} },
106106

107107
// 300... Validation Errors
108-
{ "M300", { MsgLevel::LEVEL_ERROR, CRLF_B, "" } },
108+
{ "M300", { MsgLevel::LEVEL_WARNING, CRLF_B, "%TAG% must use '%URL%'" } },
109109
{ "M301", { MsgLevel::LEVEL_ERROR, CRLF_B, "Checking Pack URL of PDSC file failed:\n"\
110110
" Expected URL : '%URL1%'\n"\
111111
" Package URL : '%URL2%'" } },
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<package schemaVersion="1.4" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="PACK.xsd">
4+
<vendor>TestVendor</vendor>
5+
<url>http://www.testurl.foo/pack/</url>
6+
<name>TestUrlHttps</name>
7+
<description>TestUrlHttps</description>
8+
<repository type="git">http://github.com/ARM-software/CMSIS-Driver.git</repository>
9+
10+
<releases>
11+
<release version="2.1.0" date="2022-06-19" tag="2.1.0" url="http://github.com/ARM-software/CMSIS-Driver/archive/2.1.0.zip">
12+
Added nothing.
13+
</release>
14+
<release version="0.0.1" date="2022-06-20">
15+
Initial release of TestUrlHttps.
16+
</release>
17+
</releases>
18+
19+
<keywords>
20+
<keyword>TestUrlHttps</keyword>
21+
</keywords>
22+
23+
<conditions>
24+
<condition id="Test_Condition">
25+
<description>Test Device</description>
26+
<require Dvendor="ARM:82"/>
27+
</condition>
28+
</conditions>
29+
30+
<components>
31+
<component Cclass="TestClass" Cgroup="TestGlobal" Cversion="1.0.0" condition="Test_Condition">
32+
<description>TestGlobal</description>
33+
</component>
34+
<component Cclass="Device" Cgroup="Config Tools" Csub="Init" Cversion="1.0.0" condition="Test_Condition" generator="MyConfig">
35+
<description>Initialization generated by MyConfig</description>
36+
<files>
37+
<file category="doc" name="http://www.testurl.foo/web/myConfig"/>
38+
</files>
39+
</component>
40+
</components>
41+
42+
<devices>
43+
<family Dfamily="MyDevice Series" Dvendor="MyDevice:99">
44+
<processor Dcore="Cortex-M3" DcoreVersion="r1p1"/>
45+
<book category="overview" name="http://www.testurl.foo/web/myDevice" title="MyDevice Web Page"/>
46+
47+
<subFamily DsubFamily="MyDevice">
48+
<device Dname="MyDeviceM0">
49+
<processor Dfpu="0" Dmpu="0" Dendian="Little-endian" Dclock="24000000"/>
50+
</device>
51+
</subFamily>
52+
</family>
53+
</devices>
54+
55+
<boards>
56+
<board vendor="ARM" name="MyBoard" orderForm="http://www.testurl.foo">
57+
<description>MyBoard Evaluation Kit</description>
58+
<image small="http://www.testurl.foo/web/myBoardSmall.png"/>
59+
<book category="overview" name="http://www.testurl.foo/web/myBoard" title="MyBoard" public="true"/>
60+
</board>
61+
</boards>
62+
63+
</package>

tools/packchk/test/integtests/src/PackChkIntegTests.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,36 @@ TEST_F(PackChkIntegTests, CheckDuplicateFlashAlgo) {
764764
}
765765
}
766766

767+
// Validate URLs to start with 'https://'
768+
TEST_F(PackChkIntegTests, CheckUrlForHttp) {
769+
const char* argv[5];
770+
771+
const string& pdscFile = PackChkIntegTestEnv::localtestdata_dir +
772+
"/TestUrlHttps/TestVendor.TestUrlHttps.pdsc";
773+
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));
774+
775+
argv[0] = (char*)"";
776+
argv[1] = (char*)pdscFile.c_str();
777+
argv[2] = (char*)"--disable-validation";
778+
argv[3] = (char*)"-x";
779+
argv[4] = (char*)"!M368";
780+
781+
PackChk packChk;
782+
EXPECT_EQ(1, packChk.Check(2, argv, nullptr));
783+
784+
auto errMsgs = ErrLog::Get()->GetLogMessages();
785+
int M300_foundCnt = 0;
786+
for (const string& msg : errMsgs) {
787+
size_t s;
788+
if ((s = msg.find("M300")) != string::npos) {
789+
M300_foundCnt++;
790+
}
791+
}
792+
793+
if (M300_foundCnt != 8) {
794+
FAIL() << "error: missing message M300";
795+
}
796+
}
767797

768798
// Validate file is .md
769799
TEST_F(PackChkIntegTests, CheckDescriptionOverviewMd) {
@@ -793,7 +823,6 @@ TEST_F(PackChkIntegTests, CheckDescriptionOverviewMd) {
793823
FAIL() << "error: message M337 found";
794824
}
795825
}
796-
797826
// Validate config file vs. include path
798827
TEST_F(PackChkIntegTests, CheckConfigFileInIncludePath) {
799828
const char* argv[3];

0 commit comments

Comments
 (0)