summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle Keen <keenerd@gmail.com>2016-04-27 20:56:47 -0400
committerKyle Keen <keenerd@gmail.com>2016-04-27 21:21:20 -0400
commit8a4c1ef0b7af35ed533766baba7c275a31af0f60 (patch)
tree70265e4e173254ab6fc335d19c0137754851e775
parentc81a4e5ad1ab6858a7c7de83cc8b4d37a3a61730 (diff)
downloadnamcap-8a4c1ef0b7af35ed533766baba7c275a31af0f60.tar.gz
namcap-8a4c1ef0b7af35ed533766baba7c275a31af0f60.zip
Add check for new install hooks.
Signed-off-by: Kyle Keen <keenerd@gmail.com>
-rw-r--r--Namcap/rules/__init__.py1
-rw-r--r--Namcap/rules/externalhooks.py46
-rw-r--r--Namcap/tests/package/test_externalhooks.py87
-rw-r--r--namcap-tags2
4 files changed, 136 insertions, 0 deletions
diff --git a/Namcap/rules/__init__.py b/Namcap/rules/__init__.py
index d7b86c3..6e303f7 100644
--- a/Namcap/rules/__init__.py
+++ b/Namcap/rules/__init__.py
@@ -25,6 +25,7 @@ from . import (
anyelf,
elffiles,
emptydir,
+ externalhooks,
fhs,
filenames,
fileownership,
diff --git a/Namcap/rules/externalhooks.py b/Namcap/rules/externalhooks.py
new file mode 100644
index 0000000..aad2bd2
--- /dev/null
+++ b/Namcap/rules/externalhooks.py
@@ -0,0 +1,46 @@
+#
+# namcap rules - externalhooks
+# Copyright (C) 2016 Kyle Keen <keenerd@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+from Namcap.ruleclass import *
+
+class ExternalHooksRule(TarballRule):
+ name = "externalhooks"
+ description = "Check the .INSTALL for commands covered by hooks"
+ hooked = [
+ 'update-desktop-database',
+ 'update-mime-database',
+ 'install-info',
+ 'glib-compile-schemes',
+ 'gtk-update-icon-cache',
+ 'xdg-icon-resource',
+ 'gconfpkg',
+ 'gio-querymodules',
+ ]
+ def analyze(self, pkginfo, tar):
+ if ".INSTALL" not in tar.getnames():
+ return
+ f = tar.extractfile(".INSTALL")
+ text = f.read().decode('utf-8', 'ignore')
+ f.close()
+ for command in self.hooked:
+ if command in text:
+ self.warnings = [('external-hooks-warning', ())]
+ self.infos.append(('external-hooks-name %s', command))
+
+# vim: set ts=4 sw=4 noet:
diff --git a/Namcap/tests/package/test_externalhooks.py b/Namcap/tests/package/test_externalhooks.py
new file mode 100644
index 0000000..4d1cfcc
--- /dev/null
+++ b/Namcap/tests/package/test_externalhooks.py
@@ -0,0 +1,87 @@
+#
+# namcap tests - externalhooks rule
+# Copyright (C) 2016 Kyle Keen <keenerd@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+import os
+from Namcap.tests.makepkg import MakepkgTest
+import Namcap.rules.externalhooks
+
+class ExternalHooksTest(MakepkgTest):
+ pkgbuild_generic = """
+pkgname=__namcap_test_externalhooks
+pkgver=1.0
+pkgrel=1
+pkgdesc="A package"
+arch=('any')
+url="http://www.example.com/"
+license=('GPL')
+depends=('glibc')
+options=(emptydirs)
+install=sample.install
+source=()
+build() {
+ true
+}
+package() {
+ true
+}
+
+"""
+ install_bad = """
+post_install() {
+ update-desktop-database -q
+ gtk-update-icon-cache -q -t -f usr/share/icons/hicolor
+}
+"""
+ install_good = """
+post_install() {
+ true
+}
+"""
+ def test_bad_install(self):
+ pkgfile = "__namcap_test_externalhooks-1.0-1-any.pkg.tar"
+ with open(os.path.join(self.tmpdir, "PKGBUILD"), "w") as f:
+ f.write(self.pkgbuild_generic)
+ with open(os.path.join(self.tmpdir, "sample.install"), "w") as f:
+ f.write(self.install_bad)
+ self.run_makepkg()
+ pkg, r = self.run_rule_on_tarball(
+ os.path.join(self.tmpdir, pkgfile),
+ Namcap.rules.externalhooks.ExternalHooksRule
+ )
+ self.assertEqual(r.errors, [])
+ self.assertEqual(r.warnings, [('external-hooks-warning', ())])
+ self.assertEqual(r.infos,
+ [('external-hooks-name %s', 'update-desktop-database'),
+ ('external-hooks-name %s', 'gtk-update-icon-cache')])
+ def test_good_install(self):
+ pkgfile = "__namcap_test_externalhooks-1.0-1-any.pkg.tar"
+ with open(os.path.join(self.tmpdir, "PKGBUILD"), "w") as f:
+ f.write(self.pkgbuild_generic)
+ with open(os.path.join(self.tmpdir, "sample.install"), "w") as f:
+ f.write(self.install_good)
+ self.run_makepkg()
+ pkg, r = self.run_rule_on_tarball(
+ os.path.join(self.tmpdir, pkgfile),
+ Namcap.rules.externalhooks.ExternalHooksRule
+ )
+ self.assertEqual(r.errors, [])
+ self.assertEqual(r.warnings, [])
+ self.assertEqual(r.infos, [])
+
+# vim: set ts=4 sw=4 noet:
diff --git a/namcap-tags b/namcap-tags
index c60c88a..58139fb 100644
--- a/namcap-tags
+++ b/namcap-tags
@@ -22,6 +22,8 @@ elffile-with-textrel %s :: ELF file ('%s') has text relocations.
elffile-with-execstack %s :: ELF file ('%s') has executable stack.
empty-directory %s :: Directory (%s) is empty
error-running-rule %s :: Error running rule '%s'
+external-hooks-name %s :: .INSTALL file runs a command (%s) provided by hooks.
+external-hooks-warning :: .INSTALL file runs a command provided by hooks.
extra-var-begins-without-underscore %s :: Non standard variable '%s' doesn't start with an underscore
file-in-non-standard-dir %s :: File (%s) exists in a non-standard directory.
file-in-temporary-dir %s :: File (%s) is in a temporary directory.