1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
|
#!/usr/bin/python3
# This file is part of Cockpit.
#
# Copyright (C) 2017 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
import parent
from packagelib import *
from testlib import *
@skipImage("Not supported", "fedora-coreos")
@skipPackage("cockpit-apps")
class TestApps(PackageCase):
def setUp(self):
super().setUp()
self.appstream_collection = set()
self.machine.upload([ "verify/files/test.png" ], "/var/tmp/")
def createAppStreamPackage(self, name, version, revision):
self.createPackage(name, version, revision, content={
"/usr/share/metainfo/org.cockpit-project.{0}.metainfo.xml".format(name): """
<component type="addon">
<extends>org.cockpit_project.cockpit</extends>
<id>org.cockpit-project.{0}</id>
<icon type="local">/usr/share/pixmaps/test.png</icon>
<name>{0}</name>
<summary>An application for testing</summary>
<launchable type="cockpit-manifest">{0}</launchable>
</component>
""".format(name),
"/usr/share/pixmaps/test.png": { "path": "/var/tmp/test.png" }})
self.appstream_collection.add(name)
def createAppStreamRepoPackage(self):
body = ""
for p in self.appstream_collection:
body += """
<component type="addon">
<extends>org.cockpit_project.cockpit</extends>
<id>org.cockpit-project.{0}</id>
<icon type="cached">test.png</icon>
<name>{0}</name>
<summary>An application for testing</summary>
<launchable type="cockpit-manifest">{0}</launchable>
<description>
<p>DESCRIPTION:none</p>
</description>
<url type="homepage">https://{0}.com</url>
<pkgname>{0}</pkgname>
</component>
""".format(p)
self.machine.execute("mkdir -p /usr/share/app-info/xmls")
self.createPackage("appstream-data-test", "1.0", "1", content={
"/usr/share/app-info/xmls/test.xml": """
<components origin="test">
{0}
</components>
""".format(body),
"/usr/share/app-info/icons/test/64x64/test.png": { "path": "/var/tmp/test.png" }})
self.enableRepo()
self.machine.execute("systemctl stop packagekit && pkcon refresh force")
# ignore the corresponding journal entry
self.allow_journal_messages("org.freedesktop.PackageKit.*org.freedesktop.DBus.Error.NoReply.*")
def testBasic(self, urlroot=""):
b = self.browser
m = self.machine
# Make sure none of the appstream directories exist. They
# will be created later and we need to cope with that.
m.execute("rm -rf /usr/share/metainfo /usr/share/app-info /var/cache/app-info")
# instead of the actual distro packages, use our own fake repo data package
m.write("/usr/share/cockpit/apps/override.json",
'{ "config": { "appstream_data_packages": [ "appstream-data-test" ] } }')
if urlroot != "":
m.execute('mkdir -p /etc/cockpit/ && echo "[WebService]\nUrlRoot=%s" > /etc/cockpit/cockpit.conf' % urlroot)
m.start_cockpit()
b.login_and_go("/apps", urlroot=urlroot)
b.wait_visible(".app-list-empty")
self.createAppStreamPackage("app-1", "1.0", "1")
self.createAppStreamRepoPackage()
# Refresh package info
b.click(".ct-table-actions button")
b.click(".app-list #app-1")
b.wait_visible('.app-links a[href="https://app-1.com"]')
b.wait_visible('.app img[src^="%s/cockpit/channel/"]' % urlroot)
b.click(".pf-c-breadcrumb a:contains('Applications')")
b.wait_visible("#list-page")
b.wait_not_visible("#app-page")
b.click(".app-list .pf-c-data-list__item-row:contains('app-1') button:contains('Install')")
b.wait_visible(".app-list .pf-c-data-list__item-row:contains('app-1') button:contains('Remove')")
b.wait_visible(".app-list .pf-c-data-list__item-row:contains('app-1') img[src^='%s/cockpit/channel/']" % urlroot)
m.execute("test -f /stamp-app-1-1.0-1")
b.click(".app-list .pf-c-data-list__item-row:contains('app-1') button:contains('Remove')")
b.wait_visible(".app-list .pf-c-data-list__item-row:contains('app-1') button:contains('Install')")
b.wait_visible(".app-list .pf-c-data-list__item-row:contains('app-1') img[src^='%s/cockpit/channel/']" % urlroot)
m.execute("! test -f /stamp-app-1-1.0-1")
def testWithUrlRoot(self):
self.testBasic(urlroot="/webcon")
def testL10N(self):
b = self.browser
m = self.machine
# Switching to a language might produce these messages, which seem to be harmless.
self.allow_journal_messages("invalid or unusable locale.*",
"Error .* data: Connection reset by peer")
# Because of the reloading done by set_lang
self.allow_restart_journal_messages()
# Reset everything
m.execute("rm -rf /usr/share/metainfo /usr/share/app-info /var/cache/app-info")
m.start_cockpit()
b.login_and_go("/apps")
b.wait_visible(".app-list-empty")
m.execute("mkdir -p /usr/share/app-info/xmls")
m.write("/usr/share/app-info/xmls/test.xml", """
<components origin="test">
<component type="addon">
<extends>org.cockpit_project.cockpit</extends>
<id>org.cockpit-project.foo</id>
<name>NAME:none</name>
<name xml:lang="de">NAME:de</name>
<summary>SUMMARY:none</summary>
<summary xml:lang="de">SUMMARY:de</summary>
<description>
<p>DESCRIPTION:none</p>
<p xml:lang="de">DESCRIPTION:de</p>
</description>
<launchable type="cockpit-manifest">foo</launchable>
<pkgname>foo</pkgname>
</component>
</components>""")
b.wait_visible(".app-list .pf-c-data-list__item-row:contains('SUMMARY:none') button:contains('Install')")
b.click(".app-list .pf-c-data-list__item-row:contains('SUMMARY:none') .pf-m-inline")
b.wait_visible(".app-description:contains('DESCRIPTION:none')")
def set_lang(lang):
b.switch_to_top()
b.click("#navbar-dropdown")
b.click(".display-language-menu a")
if self.system_before(233): # Changed in #14890
b.wait_popup('display-language')
b.set_val("#display-language select", lang)
b.click("#display-language-select-button")
else:
b.wait_visible('#display-language-modal')
b.set_val("#display-language-modal select", lang)
b.click("#display-language-modal footer button.pf-m-primary")
b.expect_load()
# HACK: work around language switching in Chrome not working in current session (issue #8160)
b.reload(ignore_cache=True)
b.wait_visible("#content")
b.enter_page("/apps")
set_lang("de-de")
b.wait_visible(".app-description:contains('DESCRIPTION:de')")
b.wait_not_present(".app-description:contains('DESCRIPTION:none')")
set_lang("ja-jp")
b.wait_visible(".app-description:contains('DESCRIPTION:none')")
b.wait_not_present(".app-description:contains('DESCRIPTION:de')")
# like in the general whitelist, but translated
self.allow_journal_messages("xargs: basename: .*Signal 13.*")
def testBrokenXML(self):
b = self.browser
m = self.machine
# Reset everything
m.execute("rm -rf /usr/share/metainfo /usr/share/app-info /var/cache/app-info")
m.start_cockpit()
b.login_and_go("/apps")
b.wait_visible(".app-list-empty")
m.execute("mkdir -p /usr/share/app-info/xmls")
self.allow_journal_messages(".*/usr/share/app-info/xmls/test.xml.*",
".*xml.etree.ElementTree.ParseError.*")
def reset():
m.write("/usr/share/app-info/xmls/test.xml", """
<components origin="test">
<component type="addon">
<extends>org.cockpit_project.cockpit</extends>
<id>org.cockpit-project.test</id>
<name>Name</name>
<summary>Summary</summary>
<description>
<p>Description</p>
</description>
<launchable type="cockpit-manifest">foo</launchable>
<pkgname>foo</pkgname>
</component>
</components>""")
b.wait_not_present(".app-list-empty")
b.wait_visible(".app-list .pf-c-data-list__item-row:contains('Summary')")
# First lay down some good XML so that we can later detect the reaction to broken XML.
reset()
# Unparsable
m.write("/usr/share/app-info/xmls/test.xml", """
This <is <not XML.
""")
b.wait_visible(".app-list-empty")
reset()
# Not really AppStream
m.write("/usr/share/app-info/xmls/test.xml", """
<foo></foo>
""")
b.wait_visible(".app-list-empty")
reset()
# No origin
m.write("/usr/share/app-info/xmls/test.xml", """
<components>
<component type="addon">
<extends>org.cockpit_project.cockpit</extends>
<id>org.cockpit-project.test</id>
<name>Name</name>
<summary>Summary</summary>
<description>
<p>Description</p>
</description>
<launchable type="cockpit-manifest">foo</launchable>
<pkgname>foo</pkgname>
</component>
</components>""")
b.wait_visible(".app-list-empty")
reset()
# No package
m.write("/usr/share/app-info/xmls/test.xml", """
<components origin="test">
<component type="addon">
<extends>org.cockpit_project.cockpit</extends>
<id>org.cockpit-project.test</id>
<name>Name</name>
<summary>Summary</summary>
<description>
<p>Description</p>
</description>
<launchable type="cockpit-manifest">foo</launchable>
</component>
</components>""")
b.wait_visible(".app-list-empty")
reset()
# No id
m.write("/usr/share/app-info/xmls/test.xml", """
<components origin="test">
<component type="addon">
<extends>org.cockpit_project.cockpit</extends>
<name>Name</name>
<summary>No description</summary>
<launchable type="cockpit-manifest">foo</launchable>
<pkgname>foo</pkgname>
</component>
</components>""")
b.wait_visible(".app-list-empty")
reset()
# Error (launchable without type) in earlier entry, shouldn't affect the later entry
m.write("/usr/share/app-info/xmls/test.xml", """
<components origin="test">
<component type="addon">
<extends>org.cockpit_project.cockpit</extends>
<id>org.cockpit-project.test2</id>
<name>Name</name>
<summary>Summary</summary>
<description>
<p>Description 2</p>
</description>
<launchable>foo</launchable>
<pkgname>foo</pkgname>
</component>
<component type="addon">
<extends>org.cockpit_project.cockpit</extends>
<id>org.cockpit-project.test</id>
<name>Name</name>
<summary>Summary 2</summary>
<description>
<p>Description</p>
</description>
<launchable type="cockpit-manifest">foo</launchable>
<pkgname>foo</pkgname>
</component>
</components>""")
b.wait_not_present(".app-list-empty")
b.wait_visible(".app-list .pf-c-data-list__item-row:contains('Summary 2')")
if __name__ == '__main__':
test_main()
|