| 1 |
# vim: set ft=python ts=4 sw=4 expandtab: |
| 2 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 3 |
# |
| 4 |
# C E D A R |
| 5 |
# S O L U T I O N S "Software done right." |
| 6 |
# S O F T W A R E |
| 7 |
# |
| 8 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 9 |
# |
| 10 |
# Copyright (c) 2007,2010,2015 Kenneth J. Pronovici. |
| 11 |
# All rights reserved. |
| 12 |
# |
| 13 |
# This program is free software; you can redistribute it and/or |
| 14 |
# modify it under the terms of the GNU General Public License, |
| 15 |
# Version 2, as published by the Free Software Foundation. |
| 16 |
# |
| 17 |
# This program is distributed in the hope that it will be useful, |
| 18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 20 |
# |
| 21 |
# Copies of the GNU General Public License are available from |
| 22 |
# the Free Software Foundation website, http://www.gnu.org/. |
| 23 |
# |
| 24 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 25 |
# |
| 26 |
# Author : Kenneth J. Pronovici <[email protected]> |
| 27 |
# Language : Python 3 |
| 28 |
# Project : Cedar Backup, release 3 |
| 29 |
# Purpose : Tests encrypt extension functionality. |
| 30 |
# |
| 31 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 32 |
|
| 33 |
######################################################################## |
| 34 |
# Module documentation |
| 35 |
######################################################################## |
| 36 |
|
| 37 |
""" |
| 38 |
Unit tests for CedarBackup3/extend/encrypt.py. |
| 39 |
|
| 40 |
Code Coverage |
| 41 |
============= |
| 42 |
|
| 43 |
This module contains individual tests for the the public classes implemented |
| 44 |
in extend/encrypt.py. There are also tests for some of the private |
| 45 |
functions. |
| 46 |
|
| 47 |
Naming Conventions |
| 48 |
================== |
| 49 |
|
| 50 |
I prefer to avoid large unit tests which validate more than one piece of |
| 51 |
functionality, and I prefer to avoid using overly descriptive (read: long) |
| 52 |
test names, as well. Instead, I use lots of very small tests that each |
| 53 |
validate one specific thing. These small tests are then named with an index |
| 54 |
number, yielding something like ``testAddDir_001`` or ``testValidate_010``. |
| 55 |
Each method has a docstring describing what it's supposed to accomplish. I |
| 56 |
feel that this makes it easier to judge how important a given failure is, |
| 57 |
and also makes it somewhat easier to diagnose and fix individual problems. |
| 58 |
|
| 59 |
Testing XML Extraction |
| 60 |
====================== |
| 61 |
|
| 62 |
It's difficult to validated that generated XML is exactly "right", |
| 63 |
especially when dealing with pretty-printed XML. We can't just provide a |
| 64 |
constant string and say "the result must match this". Instead, what we do |
| 65 |
is extract a node, build some XML from it, and then feed that XML back into |
| 66 |
another object's constructor. If that parse process succeeds and the old |
| 67 |
object is equal to the new object, we assume that the extract was |
| 68 |
successful. |
| 69 |
|
| 70 |
It would arguably be better if we could do a completely independent check - |
| 71 |
but implementing that check would be equivalent to re-implementing all of |
| 72 |
the existing functionality that we're validating here! After all, the most |
| 73 |
important thing is that data can move seamlessly from object to XML document |
| 74 |
and back to object. |
| 75 |
|
| 76 |
Full vs. Reduced Tests |
| 77 |
====================== |
| 78 |
|
| 79 |
Some Cedar Backup regression tests require a specialized environment in |
| 80 |
order to run successfully. This environment won't necessarily be available |
| 81 |
on every build system out there (for instance, on a Debian autobuilder). |
| 82 |
Because of this, the default behavior is to run a "reduced feature set" test |
| 83 |
suite that has no surprising system, kernel or network requirements. If you |
| 84 |
want to run all of the tests, set ENCRYPTTESTS_FULL to "Y" in the environment. |
| 85 |
|
| 86 |
In this module, the primary dependency is that for some tests, GPG must have |
| 87 |
access to the public key EFD75934. There is also an assumption that GPG |
| 88 |
does *not* have access to a public key for anyone named "Bogus J. User" (so |
| 89 |
we can test failure scenarios). |
| 90 |
|
| 91 |
@author Kenneth J. Pronovici <[email protected]> |
| 92 |
""" |
| 93 |
|
| 94 |
|
| 95 |
######################################################################## |
| 96 |
# Import modules and do runtime validations |
| 97 |
######################################################################## |
| 98 |
|
| 99 |
import os |
| 100 |
import tempfile |
| 101 |
import unittest |
| 102 |
|
| 103 |
from CedarBackup3.extend.encrypt import EncryptConfig, LocalConfig, _encryptDailyDir, _encryptFile, _encryptFileWithGpg |
| 104 |
from CedarBackup3.filesystem import FilesystemList |
| 105 |
from CedarBackup3.testutil import buildPath, configureLogging, extractTar, failUnlessAssignRaises, findResources, removedir |
| 106 |
from CedarBackup3.xmlutil import createOutputDom, serializeDom |
| 107 |
|
| 108 |
####################################################################### |
| 109 |
# Module-wide configuration and constants |
| 110 |
####################################################################### |
| 111 |
|
| 112 |
DATA_DIRS = [ |
| 113 |
"./data", |
| 114 |
"./tests/data", |
| 115 |
] |
| 116 |
RESOURCES = [ |
| 117 |
"encrypt.conf.1", |
| 118 |
"encrypt.conf.2", |
| 119 |
"tree1.tar.gz", |
| 120 |
"tree2.tar.gz", |
| 121 |
"tree8.tar.gz", |
| 122 |
"tree15.tar.gz", |
| 123 |
"tree16.tar.gz", |
| 124 |
"tree17.tar.gz", |
| 125 |
"tree18.tar.gz", |
| 126 |
"tree19.tar.gz", |
| 127 |
"tree20.tar.gz", |
| 128 |
] |
| 129 |
|
| 130 |
VALID_GPG_RECIPIENT = "EFD75934" |
| 131 |
INVALID_GPG_RECIPIENT = "Bogus J. User" |
| 132 |
|
| 133 |
INVALID_PATH = "bogus" # This path name should never exist |
| 134 |
|
| 135 |
|
| 136 |
####################################################################### |
| 137 |
# Utility functions |
| 138 |
####################################################################### |
| 139 |
|
| 140 |
|
| 141 |
def runAllTests(): |
| 142 |
"""Returns true/false depending on whether the full test suite should be run.""" |
| 143 |
if "ENCRYPTTESTS_FULL" in os.environ: |
| 144 |
return os.environ["ENCRYPTTESTS_FULL"] == "Y" |
| 145 |
else: |
| 146 |
return False |
| 147 |
|
| 148 |
|
| 149 |
####################################################################### |
| 150 |
# Test Case Classes |
| 151 |
####################################################################### |
| 152 |
|
| 153 |
########################## |
| 154 |
# TestEncryptConfig class |
| 155 |
########################## |
| 156 |
|
| 157 |
|
| 158 |
class TestEncryptConfig(unittest.TestCase): |
| 159 |
"""Tests for the EncryptConfig class.""" |
| 160 |
|
| 161 |
################ |
| 162 |
# Setup methods |
| 163 |
################ |
| 164 |
|
| 165 |
@classmethod |
| 166 |
def setUpClass(cls): |
| 167 |
configureLogging() |
| 168 |
|
| 169 |
################## |
| 170 |
# Utility methods |
| 171 |
################## |
| 172 |
|
| 173 |
def failUnlessAssignRaises(self, exception, obj, prop, value): |
| 174 |
"""Equivalent of :any:`failUnlessRaises`, but used for property assignments instead.""" |
| 175 |
failUnlessAssignRaises(self, exception, obj, prop, value) |
| 176 |
|
| 177 |
############################ |
| 178 |
# Test __repr__ and __str__ |
| 179 |
############################ |
| 180 |
|
| 181 |
def testStringFuncs_001(self): |
| 182 |
""" |
| 183 |
Just make sure that the string functions don't have errors (i.e. bad variable names). |
| 184 |
""" |
| 185 |
obj = EncryptConfig() |
| 186 |
obj.__repr__() |
| 187 |
obj.__str__() |
| 188 |
|
| 189 |
################################## |
| 190 |
# Test constructor and attributes |
| 191 |
################################## |
| 192 |
|
| 193 |
def testConstructor_001(self): |
| 194 |
""" |
| 195 |
Test constructor with no values filled in. |
| 196 |
""" |
| 197 |
encrypt = EncryptConfig() |
| 198 |
self.assertEqual(None, encrypt.encryptMode) |
| 199 |
self.assertEqual(None, encrypt.encryptTarget) |
| 200 |
|
| 201 |
def testConstructor_002(self): |
| 202 |
""" |
| 203 |
Test constructor with all values filled in, with valid values. |
| 204 |
""" |
| 205 |
encrypt = EncryptConfig("gpg", "Backup User") |
| 206 |
self.assertEqual("gpg", encrypt.encryptMode) |
| 207 |
self.assertEqual("Backup User", encrypt.encryptTarget) |
| 208 |
|
| 209 |
def testConstructor_003(self): |
| 210 |
""" |
| 211 |
Test assignment of encryptMode attribute, None value. |
| 212 |
""" |
| 213 |
encrypt = EncryptConfig(encryptMode="gpg") |
| 214 |
self.assertEqual("gpg", encrypt.encryptMode) |
| 215 |
encrypt.encryptMode = None |
| 216 |
self.assertEqual(None, encrypt.encryptMode) |
| 217 |
|
| 218 |
def testConstructor_004(self): |
| 219 |
""" |
| 220 |
Test assignment of encryptMode attribute, valid value. |
| 221 |
""" |
| 222 |
encrypt = EncryptConfig() |
| 223 |
self.assertEqual(None, encrypt.encryptMode) |
| 224 |
encrypt.encryptMode = "gpg" |
| 225 |
self.assertEqual("gpg", encrypt.encryptMode) |
| 226 |
|
| 227 |
def testConstructor_005(self): |
| 228 |
""" |
| 229 |
Test assignment of encryptMode attribute, invalid value (empty). |
| 230 |
""" |
| 231 |
encrypt = EncryptConfig() |
| 232 |
self.assertEqual(None, encrypt.encryptMode) |
| 233 |
self.failUnlessAssignRaises(ValueError, encrypt, "encryptMode", "") |
| 234 |
self.assertEqual(None, encrypt.encryptMode) |
| 235 |
|
| 236 |
def testConstructor_006(self): |
| 237 |
""" |
| 238 |
Test assignment of encryptTarget attribute, None value. |
| 239 |
""" |
| 240 |
encrypt = EncryptConfig(encryptTarget="Backup User") |
| 241 |
self.assertEqual("Backup User", encrypt.encryptTarget) |
| 242 |
encrypt.encryptTarget = None |
| 243 |
self.assertEqual(None, encrypt.encryptTarget) |
| 244 |
|
| 245 |
def testConstructor_007(self): |
| 246 |
""" |
| 247 |
Test assignment of encryptTarget attribute, valid value. |
| 248 |
""" |
| 249 |
encrypt = EncryptConfig() |
| 250 |
self.assertEqual(None, encrypt.encryptTarget) |
| 251 |
encrypt.encryptTarget = "Backup User" |
| 252 |
self.assertEqual("Backup User", encrypt.encryptTarget) |
| 253 |
|
| 254 |
def testConstructor_008(self): |
| 255 |
""" |
| 256 |
Test assignment of encryptTarget attribute, invalid value (empty). |
| 257 |
""" |
| 258 |
encrypt = EncryptConfig() |
| 259 |
self.assertEqual(None, encrypt.encryptTarget) |
| 260 |
self.failUnlessAssignRaises(ValueError, encrypt, "encryptTarget", "") |
| 261 |
self.assertEqual(None, encrypt.encryptTarget) |
| 262 |
|
| 263 |
############################ |
| 264 |
# Test comparison operators |
| 265 |
############################ |
| 266 |
|
| 267 |
def testComparison_001(self): |
| 268 |
""" |
| 269 |
Test comparison of two identical objects, all attributes None. |
| 270 |
""" |
| 271 |
encrypt1 = EncryptConfig() |
| 272 |
encrypt2 = EncryptConfig() |
| 273 |
self.assertEqual(encrypt1, encrypt2) |
| 274 |
self.assertTrue(encrypt1 == encrypt2) |
| 275 |
self.assertTrue(not encrypt1 < encrypt2) |
| 276 |
self.assertTrue(encrypt1 <= encrypt2) |
| 277 |
self.assertTrue(not encrypt1 > encrypt2) |
| 278 |
self.assertTrue(encrypt1 >= encrypt2) |
| 279 |
self.assertTrue(not encrypt1 != encrypt2) |
| 280 |
|
| 281 |
def testComparison_002(self): |
| 282 |
""" |
| 283 |
Test comparison of two identical objects, all attributes non-None. |
| 284 |
""" |
| 285 |
encrypt1 = EncryptConfig("gpg", "Backup User") |
| 286 |
encrypt2 = EncryptConfig("gpg", "Backup User") |
| 287 |
self.assertEqual(encrypt1, encrypt2) |
| 288 |
self.assertTrue(encrypt1 == encrypt2) |
| 289 |
self.assertTrue(not encrypt1 < encrypt2) |
| 290 |
self.assertTrue(encrypt1 <= encrypt2) |
| 291 |
self.assertTrue(not encrypt1 > encrypt2) |
| 292 |
self.assertTrue(encrypt1 >= encrypt2) |
| 293 |
self.assertTrue(not encrypt1 != encrypt2) |
| 294 |
|
| 295 |
def testComparison_003(self): |
| 296 |
""" |
| 297 |
Test comparison of two differing objects, encryptMode differs (one None). |
| 298 |
""" |
| 299 |
encrypt1 = EncryptConfig() |
| 300 |
encrypt2 = EncryptConfig(encryptMode="gpg") |
| 301 |
self.assertNotEqual(encrypt1, encrypt2) |
| 302 |
self.assertTrue(not encrypt1 == encrypt2) |
| 303 |
self.assertTrue(encrypt1 < encrypt2) |
| 304 |
self.assertTrue(encrypt1 <= encrypt2) |
| 305 |
self.assertTrue(not encrypt1 > encrypt2) |
| 306 |
self.assertTrue(not encrypt1 >= encrypt2) |
| 307 |
self.assertTrue(encrypt1 != encrypt2) |
| 308 |
|
| 309 |
# Note: no test to check when encrypt mode differs, since only one value is allowed |
| 310 |
|
| 311 |
def testComparison_004(self): |
| 312 |
""" |
| 313 |
Test comparison of two differing objects, encryptTarget differs (one None). |
| 314 |
""" |
| 315 |
encrypt1 = EncryptConfig() |
| 316 |
encrypt2 = EncryptConfig(encryptTarget="Backup User") |
| 317 |
self.assertNotEqual(encrypt1, encrypt2) |
| 318 |
self.assertTrue(not encrypt1 == encrypt2) |
| 319 |
self.assertTrue(encrypt1 < encrypt2) |
| 320 |
self.assertTrue(encrypt1 <= encrypt2) |
| 321 |
self.assertTrue(not encrypt1 > encrypt2) |
| 322 |
self.assertTrue(not encrypt1 >= encrypt2) |
| 323 |
self.assertTrue(encrypt1 != encrypt2) |
| 324 |
|
| 325 |
def testComparison_005(self): |
| 326 |
""" |
| 327 |
Test comparison of two differing objects, encryptTarget differs. |
| 328 |
""" |
| 329 |
encrypt1 = EncryptConfig("gpg", "Another User") |
| 330 |
encrypt2 = EncryptConfig("gpg", "Backup User") |
| 331 |
self.assertNotEqual(encrypt1, encrypt2) |
| 332 |
self.assertTrue(not encrypt1 == encrypt2) |
| 333 |
self.assertTrue(encrypt1 < encrypt2) |
| 334 |
self.assertTrue(encrypt1 <= encrypt2) |
| 335 |
self.assertTrue(not encrypt1 > encrypt2) |
| 336 |
self.assertTrue(not encrypt1 >= encrypt2) |
| 337 |
self.assertTrue(encrypt1 != encrypt2) |
| 338 |
|
| 339 |
|
| 340 |
######################## |
| 341 |
# TestLocalConfig class |
| 342 |
######################## |
| 343 |
|
| 344 |
|
| 345 |
class TestLocalConfig(unittest.TestCase): |
| 346 |
"""Tests for the LocalConfig class.""" |
| 347 |
|
| 348 |
################ |
| 349 |
# Setup methods |
| 350 |
################ |
| 351 |
|
| 352 |
@classmethod |
| 353 |
def setUpClass(cls): |
| 354 |
configureLogging() |
| 355 |
|
| 356 |
def setUp(self): |
| 357 |
try: |
| 358 |
self.resources = findResources(RESOURCES, DATA_DIRS) |
| 359 |
except Exception as e: |
| 360 |
self.fail(e) |
| 361 |
|
| 362 |
def tearDown(self): |
| 363 |
pass |
| 364 |
|
| 365 |
################## |
| 366 |
# Utility methods |
| 367 |
################## |
| 368 |
|
| 369 |
def failUnlessAssignRaises(self, exception, obj, prop, value): |
| 370 |
"""Equivalent of :any:`failUnlessRaises`, but used for property assignments instead.""" |
| 371 |
failUnlessAssignRaises(self, exception, obj, prop, value) |
| 372 |
|
| 373 |
def validateAddConfig(self, origConfig): |
| 374 |
""" |
| 375 |
Validates that document dumped from ``LocalConfig.addConfig`` results in |
| 376 |
identical object. |
| 377 |
|
| 378 |
We dump a document containing just the encrypt configuration, and then |
| 379 |
make sure that if we push that document back into the ``LocalConfig`` |
| 380 |
object, that the resulting object matches the original. |
| 381 |
|
| 382 |
The ``self.failUnlessEqual`` method is used for the validation, so if the |
| 383 |
method call returns normally, everything is OK. |
| 384 |
|
| 385 |
Args: |
| 386 |
origConfig: Original configuration |
| 387 |
""" |
| 388 |
(xmlDom, parentNode) = createOutputDom() |
| 389 |
origConfig.addConfig(xmlDom, parentNode) |
| 390 |
xmlData = serializeDom(xmlDom) |
| 391 |
newConfig = LocalConfig(xmlData=xmlData, validate=False) |
| 392 |
self.assertEqual(origConfig, newConfig) |
| 393 |
|
| 394 |
############################ |
| 395 |
# Test __repr__ and __str__ |
| 396 |
############################ |
| 397 |
|
| 398 |
def testStringFuncs_001(self): |
| 399 |
""" |
| 400 |
Just make sure that the string functions don't have errors (i.e. bad variable names). |
| 401 |
""" |
| 402 |
obj = LocalConfig() |
| 403 |
obj.__repr__() |
| 404 |
obj.__str__() |
| 405 |
|
| 406 |
##################################################### |
| 407 |
# Test basic constructor and attribute functionality |
| 408 |
##################################################### |
| 409 |
|
| 410 |
def testConstructor_001(self): |
| 411 |
""" |
| 412 |
Test empty constructor, validate=False. |
| 413 |
""" |
| 414 |
config = LocalConfig(validate=False) |
| 415 |
self.assertEqual(None, config.encrypt) |
| 416 |
|
| 417 |
def testConstructor_002(self): |
| 418 |
""" |
| 419 |
Test empty constructor, validate=True. |
| 420 |
""" |
| 421 |
config = LocalConfig(validate=True) |
| 422 |
self.assertEqual(None, config.encrypt) |
| 423 |
|
| 424 |
def testConstructor_003(self): |
| 425 |
""" |
| 426 |
Test with empty config document as both data and file, validate=False. |
| 427 |
""" |
| 428 |
path = self.resources["encrypt.conf.1"] |
| 429 |
with open(path) as f: |
| 430 |
contents = f.read() |
| 431 |
self.assertRaises(ValueError, LocalConfig, xmlData=contents, xmlPath=path, validate=False) |
| 432 |
|
| 433 |
def testConstructor_004(self): |
| 434 |
""" |
| 435 |
Test assignment of encrypt attribute, None value. |
| 436 |
""" |
| 437 |
config = LocalConfig() |
| 438 |
config.encrypt = None |
| 439 |
self.assertEqual(None, config.encrypt) |
| 440 |
|
| 441 |
def testConstructor_005(self): |
| 442 |
""" |
| 443 |
Test assignment of encrypt attribute, valid value. |
| 444 |
""" |
| 445 |
config = LocalConfig() |
| 446 |
config.encrypt = EncryptConfig() |
| 447 |
self.assertEqual(EncryptConfig(), config.encrypt) |
| 448 |
|
| 449 |
def testConstructor_006(self): |
| 450 |
""" |
| 451 |
Test assignment of encrypt attribute, invalid value (not EncryptConfig). |
| 452 |
""" |
| 453 |
config = LocalConfig() |
| 454 |
self.failUnlessAssignRaises(ValueError, config, "encrypt", "STRING!") |
| 455 |
|
| 456 |
############################ |
| 457 |
# Test comparison operators |
| 458 |
############################ |
| 459 |
|
| 460 |
def testComparison_001(self): |
| 461 |
""" |
| 462 |
Test comparison of two identical objects, all attributes None. |
| 463 |
""" |
| 464 |
config1 = LocalConfig() |
| 465 |
config2 = LocalConfig() |
| 466 |
self.assertEqual(config1, config2) |
| 467 |
self.assertTrue(config1 == config2) |
| 468 |
self.assertTrue(not config1 < config2) |
| 469 |
self.assertTrue(config1 <= config2) |
| 470 |
self.assertTrue(not config1 > config2) |
| 471 |
self.assertTrue(config1 >= config2) |
| 472 |
self.assertTrue(not config1 != config2) |
| 473 |
|
| 474 |
def testComparison_002(self): |
| 475 |
""" |
| 476 |
Test comparison of two identical objects, all attributes non-None. |
| 477 |
""" |
| 478 |
config1 = LocalConfig() |
| 479 |
config1.encrypt = EncryptConfig() |
| 480 |
|
| 481 |
config2 = LocalConfig() |
| 482 |
config2.encrypt = EncryptConfig() |
| 483 |
|
| 484 |
self.assertEqual(config1, config2) |
| 485 |
self.assertTrue(config1 == config2) |
| 486 |
self.assertTrue(not config1 < config2) |
| 487 |
self.assertTrue(config1 <= config2) |
| 488 |
self.assertTrue(not config1 > config2) |
| 489 |
self.assertTrue(config1 >= config2) |
| 490 |
self.assertTrue(not config1 != config2) |
| 491 |
|
| 492 |
def testComparison_003(self): |
| 493 |
""" |
| 494 |
Test comparison of two differing objects, encrypt differs (one None). |
| 495 |
""" |
| 496 |
config1 = LocalConfig() |
| 497 |
config2 = LocalConfig() |
| 498 |
config2.encrypt = EncryptConfig() |
| 499 |
self.assertNotEqual(config1, config2) |
| 500 |
self.assertTrue(not config1 == config2) |
| 501 |
self.assertTrue(config1 < config2) |
| 502 |
self.assertTrue(config1 <= config2) |
| 503 |
self.assertTrue(not config1 > config2) |
| 504 |
self.assertTrue(not config1 >= config2) |
| 505 |
self.assertTrue(config1 != config2) |
| 506 |
|
| 507 |
def testComparison_004(self): |
| 508 |
""" |
| 509 |
Test comparison of two differing objects, encrypt differs. |
| 510 |
""" |
| 511 |
config1 = LocalConfig() |
| 512 |
config1.encrypt = EncryptConfig(encryptTarget="Another User") |
| 513 |
|
| 514 |
config2 = LocalConfig() |
| 515 |
config2.encrypt = EncryptConfig(encryptTarget="Backup User") |
| 516 |
|
| 517 |
self.assertNotEqual(config1, config2) |
| 518 |
self.assertTrue(not config1 == config2) |
| 519 |
self.assertTrue(config1 < config2) |
| 520 |
self.assertTrue(config1 <= config2) |
| 521 |
self.assertTrue(not config1 > config2) |
| 522 |
self.assertTrue(not config1 >= config2) |
| 523 |
self.assertTrue(config1 != config2) |
| 524 |
|
| 525 |
###################### |
| 526 |
# Test validate logic |
| 527 |
###################### |
| 528 |
|
| 529 |
def testValidate_001(self): |
| 530 |
""" |
| 531 |
Test validate on a None encrypt section. |
| 532 |
""" |
| 533 |
config = LocalConfig() |
| 534 |
config.encrypt = None |
| 535 |
self.assertRaises(ValueError, config.validate) |
| 536 |
|
| 537 |
def testValidate_002(self): |
| 538 |
""" |
| 539 |
Test validate on an empty encrypt section. |
| 540 |
""" |
| 541 |
config = LocalConfig() |
| 542 |
config.encrypt = EncryptConfig() |
| 543 |
self.assertRaises(ValueError, config.validate) |
| 544 |
|
| 545 |
def testValidate_003(self): |
| 546 |
""" |
| 547 |
Test validate on a non-empty encrypt section with no values filled in. |
| 548 |
""" |
| 549 |
config = LocalConfig() |
| 550 |
config.encrypt = EncryptConfig(None, None) |
| 551 |
self.assertRaises(ValueError, config.validate) |
| 552 |
|
| 553 |
def testValidate_004(self): |
| 554 |
""" |
| 555 |
Test validate on a non-empty encrypt section with only one value filled in. |
| 556 |
""" |
| 557 |
config = LocalConfig() |
| 558 |
config.encrypt = EncryptConfig("gpg", None) |
| 559 |
self.assertRaises(ValueError, config.validate) |
| 560 |
config.encrypt = EncryptConfig(None, "Backup User") |
| 561 |
self.assertRaises(ValueError, config.validate) |
| 562 |
|
| 563 |
def testValidate_005(self): |
| 564 |
""" |
| 565 |
Test validate on a non-empty encrypt section with valid values filled in. |
| 566 |
""" |
| 567 |
config = LocalConfig() |
| 568 |
config.encrypt = EncryptConfig("gpg", "Backup User") |
| 569 |
config.validate() |
| 570 |
|
| 571 |
############################ |
| 572 |
# Test parsing of documents |
| 573 |
############################ |
| 574 |
|
| 575 |
def testParse_001(self): |
| 576 |
""" |
| 577 |
Parse empty config document. |
| 578 |
""" |
| 579 |
path = self.resources["encrypt.conf.1"] |
| 580 |
with open(path) as f: |
| 581 |
contents = f.read() |
| 582 |
self.assertRaises(ValueError, LocalConfig, xmlPath=path, validate=True) |
| 583 |
self.assertRaises(ValueError, LocalConfig, xmlData=contents, validate=True) |
| 584 |
config = LocalConfig(xmlPath=path, validate=False) |
| 585 |
self.assertEqual(None, config.encrypt) |
| 586 |
config = LocalConfig(xmlData=contents, validate=False) |
| 587 |
self.assertEqual(None, config.encrypt) |
| 588 |
|
| 589 |
def testParse_002(self): |
| 590 |
""" |
| 591 |
Parse config document with filled-in values. |
| 592 |
""" |
| 593 |
path = self.resources["encrypt.conf.2"] |
| 594 |
with open(path) as f: |
| 595 |
contents = f.read() |
| 596 |
config = LocalConfig(xmlPath=path, validate=False) |
| 597 |
self.assertNotEqual(None, config.encrypt) |
| 598 |
self.assertEqual("gpg", config.encrypt.encryptMode) |
| 599 |
self.assertEqual("Backup User", config.encrypt.encryptTarget) |
| 600 |
config = LocalConfig(xmlData=contents, validate=False) |
| 601 |
self.assertNotEqual(None, config.encrypt) |
| 602 |
self.assertEqual("gpg", config.encrypt.encryptMode) |
| 603 |
self.assertEqual("Backup User", config.encrypt.encryptTarget) |
| 604 |
|
| 605 |
################### |
| 606 |
# Test addConfig() |
| 607 |
################### |
| 608 |
|
| 609 |
def testAddConfig_001(self): |
| 610 |
""" |
| 611 |
Test with empty config document. |
| 612 |
""" |
| 613 |
encrypt = EncryptConfig() |
| 614 |
config = LocalConfig() |
| 615 |
config.encrypt = encrypt |
| 616 |
self.validateAddConfig(config) |
| 617 |
|
| 618 |
def testAddConfig_002(self): |
| 619 |
""" |
| 620 |
Test with values set. |
| 621 |
""" |
| 622 |
encrypt = EncryptConfig(encryptMode="gpg", encryptTarget="Backup User") |
| 623 |
config = LocalConfig() |
| 624 |
config.encrypt = encrypt |
| 625 |
self.validateAddConfig(config) |
| 626 |
|
| 627 |
|
| 628 |
###################### |
| 629 |
# TestFunctions class |
| 630 |
###################### |
| 631 |
|
| 632 |
|
| 633 |
@unittest.skipUnless(runAllTests(), "Limited test suite") |
| 634 |
class TestFunctions(unittest.TestCase): |
| 635 |
"""Tests for the functions in encrypt.py.""" |
| 636 |
|
| 637 |
################ |
| 638 |
# Setup methods |
| 639 |
################ |
| 640 |
|
| 641 |
@classmethod |
| 642 |
def setUpClass(cls): |
| 643 |
configureLogging() |
| 644 |
|
| 645 |
def setUp(self): |
| 646 |
try: |
| 647 |
self.tmpdir = tempfile.mkdtemp() |
| 648 |
self.resources = findResources(RESOURCES, DATA_DIRS) |
| 649 |
except Exception as e: |
| 650 |
self.fail(e) |
| 651 |
|
| 652 |
def tearDown(self): |
| 653 |
try: |
| 654 |
removedir(self.tmpdir) |
| 655 |
except: |
| 656 |
pass |
| 657 |
|
| 658 |
################## |
| 659 |
# Utility methods |
| 660 |
################## |
| 661 |
|
| 662 |
def extractTar(self, tarname): |
| 663 |
"""Extracts a tarfile with a particular name.""" |
| 664 |
extractTar(self.tmpdir, self.resources["%s.tar.gz" % tarname]) |
| 665 |
|
| 666 |
def buildPath(self, components): |
| 667 |
"""Builds a complete search path from a list of components.""" |
| 668 |
components.insert(0, self.tmpdir) |
| 669 |
return buildPath(components) |
| 670 |
|
| 671 |
############################# |
| 672 |
# Test _encryptFileWithGpg() |
| 673 |
############################# |
| 674 |
|
| 675 |
def testEncryptFileWithGpg_001(self): |
| 676 |
""" |
| 677 |
Test for a non-existent file in a non-existent directory. |
| 678 |
""" |
| 679 |
sourceFile = self.buildPath([INVALID_PATH, INVALID_PATH]) |
| 680 |
self.assertRaises(IOError, _encryptFileWithGpg, sourceFile, INVALID_GPG_RECIPIENT) |
| 681 |
|
| 682 |
def testEncryptFileWithGpg_002(self): |
| 683 |
""" |
| 684 |
Test for a non-existent file in an existing directory. |
| 685 |
""" |
| 686 |
self.extractTar("tree8") |
| 687 |
sourceFile = self.buildPath(["tree8", "dir001", INVALID_PATH]) |
| 688 |
self.assertRaises(IOError, _encryptFileWithGpg, sourceFile, INVALID_GPG_RECIPIENT) |
| 689 |
|
| 690 |
def testEncryptFileWithGpg_003(self): |
| 691 |
""" |
| 692 |
Test for an unknown recipient. |
| 693 |
""" |
| 694 |
self.extractTar("tree1") |
| 695 |
sourceFile = self.buildPath(["tree1", "file001"]) |
| 696 |
expectedFile = self.buildPath(["tree1", "file001.gpg"]) |
| 697 |
self.assertRaises(IOError, _encryptFileWithGpg, sourceFile, INVALID_GPG_RECIPIENT) |
| 698 |
self.assertFalse(os.path.exists(expectedFile)) |
| 699 |
self.assertTrue(os.path.exists(sourceFile)) |
| 700 |
|
| 701 |
def testEncryptFileWithGpg_004(self): |
| 702 |
""" |
| 703 |
Test for a valid recipient. |
| 704 |
""" |
| 705 |
self.extractTar("tree1") |
| 706 |
sourceFile = self.buildPath(["tree1", "file001"]) |
| 707 |
expectedFile = self.buildPath(["tree1", "file001.gpg"]) |
| 708 |
actualFile = _encryptFileWithGpg(sourceFile, VALID_GPG_RECIPIENT) |
| 709 |
self.assertEqual(actualFile, expectedFile) |
| 710 |
self.assertTrue(os.path.exists(sourceFile)) |
| 711 |
self.assertTrue(os.path.exists(actualFile)) |
| 712 |
|
| 713 |
###################### |
| 714 |
# Test _encryptFile() |
| 715 |
###################### |
| 716 |
|
| 717 |
def testEncryptFile_001(self): |
| 718 |
""" |
| 719 |
Test for a mode other than "gpg". |
| 720 |
""" |
| 721 |
self.extractTar("tree1") |
| 722 |
sourceFile = self.buildPath(["tree1", "file001"]) |
| 723 |
expectedFile = self.buildPath(["tree1", "file001.gpg"]) |
| 724 |
self.assertRaises(ValueError, _encryptFile, sourceFile, "pgp", INVALID_GPG_RECIPIENT, None, None, removeSource=False) |
| 725 |
self.assertTrue(os.path.exists(sourceFile)) |
| 726 |
self.assertFalse(os.path.exists(expectedFile)) |
| 727 |
|
| 728 |
def testEncryptFile_002(self): |
| 729 |
""" |
| 730 |
Test for a source path that does not exist. |
| 731 |
""" |
| 732 |
self.extractTar("tree1") |
| 733 |
sourceFile = self.buildPath(["tree1", INVALID_PATH]) |
| 734 |
expectedFile = self.buildPath(["tree1", "%s.gpg" % INVALID_PATH]) |
| 735 |
self.assertRaises(ValueError, _encryptFile, sourceFile, "gpg", INVALID_GPG_RECIPIENT, None, None, removeSource=False) |
| 736 |
self.assertFalse(os.path.exists(sourceFile)) |
| 737 |
self.assertFalse(os.path.exists(expectedFile)) |
| 738 |
|
| 739 |
def testEncryptFile_003(self): |
| 740 |
""" |
| 741 |
Test "gpg" mode with a valid source path and invalid recipient, removeSource=False. |
| 742 |
""" |
| 743 |
self.extractTar("tree1") |
| 744 |
sourceFile = self.buildPath(["tree1", "file001"]) |
| 745 |
expectedFile = self.buildPath(["tree1", "file001.gpg"]) |
| 746 |
self.assertRaises(IOError, _encryptFile, sourceFile, "gpg", INVALID_GPG_RECIPIENT, None, None, removeSource=False) |
| 747 |
self.assertTrue(os.path.exists(sourceFile)) |
| 748 |
self.assertFalse(os.path.exists(expectedFile)) |
| 749 |
|
| 750 |
def testEncryptFile_004(self): |
| 751 |
""" |
| 752 |
Test "gpg" mode with a valid source path and invalid recipient, removeSource=True. |
| 753 |
""" |
| 754 |
self.extractTar("tree1") |
| 755 |
sourceFile = self.buildPath(["tree1", "file001"]) |
| 756 |
expectedFile = self.buildPath(["tree1", "file001.gpg"]) |
| 757 |
self.assertRaises(IOError, _encryptFile, sourceFile, "gpg", INVALID_GPG_RECIPIENT, None, None, removeSource=True) |
| 758 |
self.assertTrue(os.path.exists(sourceFile)) |
| 759 |
self.assertFalse(os.path.exists(expectedFile)) |
| 760 |
|
| 761 |
def testEncryptFile_005(self): |
| 762 |
""" |
| 763 |
Test "gpg" mode with a valid source path and recipient, removeSource=False. |
| 764 |
""" |
| 765 |
self.extractTar("tree1") |
| 766 |
sourceFile = self.buildPath(["tree1", "file001"]) |
| 767 |
expectedFile = self.buildPath(["tree1", "file001.gpg"]) |
| 768 |
actualFile = _encryptFile(sourceFile, "gpg", VALID_GPG_RECIPIENT, None, None, removeSource=False) |
| 769 |
self.assertEqual(actualFile, expectedFile) |
| 770 |
self.assertTrue(os.path.exists(sourceFile)) |
| 771 |
self.assertTrue(os.path.exists(actualFile)) |
| 772 |
|
| 773 |
def testEncryptFile_006(self): |
| 774 |
""" |
| 775 |
Test "gpg" mode with a valid source path and recipient, removeSource=True. |
| 776 |
""" |
| 777 |
self.extractTar("tree1") |
| 778 |
sourceFile = self.buildPath(["tree1", "file001"]) |
| 779 |
expectedFile = self.buildPath(["tree1", "file001.gpg"]) |
| 780 |
actualFile = _encryptFile(sourceFile, "gpg", VALID_GPG_RECIPIENT, None, None, removeSource=True) |
| 781 |
self.assertEqual(actualFile, expectedFile) |
| 782 |
self.assertFalse(os.path.exists(sourceFile)) |
| 783 |
self.assertTrue(os.path.exists(actualFile)) |
| 784 |
|
| 785 |
########################## |
| 786 |
# Test _encryptDailyDir() |
| 787 |
########################## |
| 788 |
|
| 789 |
def testEncryptDailyDir_001(self): |
| 790 |
""" |
| 791 |
Test with a nonexistent daily staging directory. |
| 792 |
""" |
| 793 |
self.extractTar("tree1") |
| 794 |
dailyDir = self.buildPath(["tree1", "dir001"]) |
| 795 |
self.assertRaises(ValueError, _encryptDailyDir, dailyDir, "gpg", VALID_GPG_RECIPIENT, None, None) |
| 796 |
|
| 797 |
def testEncryptDailyDir_002(self): |
| 798 |
""" |
| 799 |
Test with a valid staging directory containing only links. |
| 800 |
""" |
| 801 |
self.extractTar("tree15") |
| 802 |
dailyDir = self.buildPath(["tree15", "dir001"]) |
| 803 |
fsList = FilesystemList() |
| 804 |
fsList.addDirContents(dailyDir) |
| 805 |
self.assertEqual(3, len(fsList)) |
| 806 |
self.assertTrue(self.buildPath(["tree15", "dir001"]) in fsList) |
| 807 |
self.assertTrue(self.buildPath(["tree15", "dir001", "link001"]) in fsList) |
| 808 |
self.assertTrue(self.buildPath(["tree15", "dir001", "link002"]) in fsList) |
| 809 |
_encryptDailyDir(dailyDir, "gpg", VALID_GPG_RECIPIENT, None, None) |
| 810 |
fsList = FilesystemList() |
| 811 |
fsList.addDirContents(dailyDir) |
| 812 |
self.assertEqual(3, len(fsList)) |
| 813 |
self.assertTrue(self.buildPath(["tree15", "dir001"]) in fsList) |
| 814 |
self.assertTrue(self.buildPath(["tree15", "dir001", "link001"]) in fsList) |
| 815 |
self.assertTrue(self.buildPath(["tree15", "dir001", "link002"]) in fsList) |
| 816 |
|
| 817 |
def testEncryptDailyDir_003(self): |
| 818 |
""" |
| 819 |
Test with a valid staging directory containing only directories. |
| 820 |
""" |
| 821 |
self.extractTar("tree2") |
| 822 |
dailyDir = self.buildPath(["tree2"]) |
| 823 |
fsList = FilesystemList() |
| 824 |
fsList.addDirContents(dailyDir) |
| 825 |
self.assertEqual(11, len(fsList)) |
| 826 |
self.assertTrue(self.buildPath(["tree2"]) in fsList) |
| 827 |
self.assertTrue(self.buildPath(["tree2", "dir001"]) in fsList) |
| 828 |
self.assertTrue(self.buildPath(["tree2", "dir002"]) in fsList) |
| 829 |
self.assertTrue(self.buildPath(["tree2", "dir003"]) in fsList) |
| 830 |
self.assertTrue(self.buildPath(["tree2", "dir004"]) in fsList) |
| 831 |
self.assertTrue(self.buildPath(["tree2", "dir005"]) in fsList) |
| 832 |
self.assertTrue(self.buildPath(["tree2", "dir006"]) in fsList) |
| 833 |
self.assertTrue(self.buildPath(["tree2", "dir007"]) in fsList) |
| 834 |
self.assertTrue(self.buildPath(["tree2", "dir008"]) in fsList) |
| 835 |
self.assertTrue(self.buildPath(["tree2", "dir009"]) in fsList) |
| 836 |
self.assertTrue(self.buildPath(["tree2", "dir010"]) in fsList) |
| 837 |
_encryptDailyDir(dailyDir, "gpg", VALID_GPG_RECIPIENT, None, None) |
| 838 |
fsList = FilesystemList() |
| 839 |
fsList.addDirContents(dailyDir) |
| 840 |
self.assertEqual(11, len(fsList)) |
| 841 |
self.assertTrue(self.buildPath(["tree2"]) in fsList) |
| 842 |
self.assertTrue(self.buildPath(["tree2", "dir001"]) in fsList) |
| 843 |
self.assertTrue(self.buildPath(["tree2", "dir002"]) in fsList) |
| 844 |
self.assertTrue(self.buildPath(["tree2", "dir003"]) in fsList) |
| 845 |
self.assertTrue(self.buildPath(["tree2", "dir004"]) in fsList) |
| 846 |
self.assertTrue(self.buildPath(["tree2", "dir005"]) in fsList) |
| 847 |
self.assertTrue(self.buildPath(["tree2", "dir006"]) in fsList) |
| 848 |
self.assertTrue(self.buildPath(["tree2", "dir007"]) in fsList) |
| 849 |
self.assertTrue(self.buildPath(["tree2", "dir008"]) in fsList) |
| 850 |
self.assertTrue(self.buildPath(["tree2", "dir009"]) in fsList) |
| 851 |
self.assertTrue(self.buildPath(["tree2", "dir010"]) in fsList) |
| 852 |
|
| 853 |
def testEncryptDailyDir_004(self): |
| 854 |
""" |
| 855 |
Test with a valid staging directory containing only files. |
| 856 |
""" |
| 857 |
self.extractTar("tree1") |
| 858 |
dailyDir = self.buildPath(["tree1"]) |
| 859 |
fsList = FilesystemList() |
| 860 |
fsList.addDirContents(dailyDir) |
| 861 |
self.assertEqual(8, len(fsList)) |
| 862 |
self.assertTrue(self.buildPath(["tree1"]) in fsList) |
| 863 |
self.assertTrue(self.buildPath(["tree1", "file001"]) in fsList) |
| 864 |
self.assertTrue(self.buildPath(["tree1", "file002"]) in fsList) |
| 865 |
self.assertTrue(self.buildPath(["tree1", "file003"]) in fsList) |
| 866 |
self.assertTrue(self.buildPath(["tree1", "file004"]) in fsList) |
| 867 |
self.assertTrue(self.buildPath(["tree1", "file005"]) in fsList) |
| 868 |
self.assertTrue(self.buildPath(["tree1", "file006"]) in fsList) |
| 869 |
self.assertTrue(self.buildPath(["tree1", "file007"]) in fsList) |
| 870 |
_encryptDailyDir(dailyDir, "gpg", VALID_GPG_RECIPIENT, None, None) |
| 871 |
fsList = FilesystemList() |
| 872 |
fsList.addDirContents(dailyDir) |
| 873 |
self.assertEqual(8, len(fsList)) |
| 874 |
self.assertTrue(self.buildPath(["tree1"]) in fsList) |
| 875 |
self.assertTrue(self.buildPath(["tree1", "file001.gpg"]) in fsList) |
| 876 |
self.assertTrue(self.buildPath(["tree1", "file002.gpg"]) in fsList) |
| 877 |
self.assertTrue(self.buildPath(["tree1", "file003.gpg"]) in fsList) |
| 878 |
self.assertTrue(self.buildPath(["tree1", "file004.gpg"]) in fsList) |
| 879 |
self.assertTrue(self.buildPath(["tree1", "file005.gpg"]) in fsList) |
| 880 |
self.assertTrue(self.buildPath(["tree1", "file006.gpg"]) in fsList) |
| 881 |
self.assertTrue(self.buildPath(["tree1", "file007.gpg"]) in fsList) |
| 882 |
|
| 883 |
def testEncryptDailyDir_005(self): |
| 884 |
""" |
| 885 |
Test with a valid staging directory containing files, directories and |
| 886 |
links, including various files that match the general Cedar Backup |
| 887 |
indicator file pattern ("cback.<something>"). |
| 888 |
""" |
| 889 |
self.extractTar("tree16") |
| 890 |
dailyDir = self.buildPath(["tree16"]) |
| 891 |
fsList = FilesystemList() |
| 892 |
fsList.addDirContents(dailyDir) |
| 893 |
self.assertEqual(122, len(fsList)) |
| 894 |
self.assertTrue(self.buildPath(["tree16"]) in fsList) |
| 895 |
self.assertTrue(self.buildPath(["tree16", "dir001"]) in fsList) |
| 896 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001"]) in fsList) |
| 897 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file001"]) in fsList) |
| 898 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file002"]) in fsList) |
| 899 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file003"]) in fsList) |
| 900 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file004"]) in fsList) |
| 901 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file005"]) in fsList) |
| 902 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file006"]) in fsList) |
| 903 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file007"]) in fsList) |
| 904 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file008"]) in fsList) |
| 905 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "link001"]) in fsList) |
| 906 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir002"]) in fsList) |
| 907 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir002", "file001"]) in fsList) |
| 908 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir002", "file002"]) in fsList) |
| 909 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir002", "file003"]) in fsList) |
| 910 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir002", "file004"]) in fsList) |
| 911 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir002", "link001"]) in fsList) |
| 912 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir003"]) in fsList) |
| 913 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir003", "file001"]) in fsList) |
| 914 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir003", "file002"]) in fsList) |
| 915 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir003", "file003"]) in fsList) |
| 916 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir003", "link001"]) in fsList) |
| 917 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir003", "link002"]) in fsList) |
| 918 |
self.assertTrue(self.buildPath(["tree16", "dir002"]) in fsList) |
| 919 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir001"]) in fsList) |
| 920 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir001", "cback.encrypt"]) in fsList) |
| 921 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir001", "file001"]) in fsList) |
| 922 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir001", "file002"]) in fsList) |
| 923 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir001", "file003"]) in fsList) |
| 924 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir001", "link001"]) in fsList) |
| 925 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002"]) in fsList) |
| 926 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "cback.encrypt"]) in fsList) |
| 927 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "file001"]) in fsList) |
| 928 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "file002"]) in fsList) |
| 929 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "file003"]) in fsList) |
| 930 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "file004"]) in fsList) |
| 931 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "file005"]) in fsList) |
| 932 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "link001"]) in fsList) |
| 933 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "link002"]) in fsList) |
| 934 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "link003"]) in fsList) |
| 935 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "link004"]) in fsList) |
| 936 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "link005"]) in fsList) |
| 937 |
self.assertTrue(self.buildPath(["tree16", "dir003"]) in fsList) |
| 938 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001"]) in fsList) |
| 939 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file001"]) in fsList) |
| 940 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file002"]) in fsList) |
| 941 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file003"]) in fsList) |
| 942 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file004"]) in fsList) |
| 943 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file005"]) in fsList) |
| 944 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file006"]) in fsList) |
| 945 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file007"]) in fsList) |
| 946 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file008"]) in fsList) |
| 947 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "link001"]) in fsList) |
| 948 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "cback."]) in fsList) |
| 949 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002"]) in fsList) |
| 950 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002", "file001"]) in fsList) |
| 951 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002", "file002"]) in fsList) |
| 952 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002", "file003"]) in fsList) |
| 953 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002", "file004"]) in fsList) |
| 954 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002", "link001"]) in fsList) |
| 955 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002", "cback.encrypt"]) in fsList) |
| 956 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003"]) in fsList) |
| 957 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "file001"]) in fsList) |
| 958 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "file002"]) in fsList) |
| 959 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "file003"]) in fsList) |
| 960 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "link001"]) in fsList) |
| 961 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "link002"]) in fsList) |
| 962 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "cback.encrypt"]) in fsList) |
| 963 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "cback.store"]) in fsList) |
| 964 |
self.assertTrue(self.buildPath(["tree16", "dir004"]) in fsList) |
| 965 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001"]) in fsList) |
| 966 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file001"]) in fsList) |
| 967 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file002"]) in fsList) |
| 968 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file003"]) in fsList) |
| 969 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file004"]) in fsList) |
| 970 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file005"]) in fsList) |
| 971 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file006"]) in fsList) |
| 972 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file007"]) in fsList) |
| 973 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file008"]) in fsList) |
| 974 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "link001"]) in fsList) |
| 975 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "cback."]) in fsList) |
| 976 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "cback.collect"]) in fsList) |
| 977 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002"]) in fsList) |
| 978 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002", "file001"]) in fsList) |
| 979 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002", "file002"]) in fsList) |
| 980 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002", "file003"]) in fsList) |
| 981 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002", "file004"]) in fsList) |
| 982 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002", "link001"]) in fsList) |
| 983 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002", "cback.encrypt"]) in fsList) |
| 984 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003"]) in fsList) |
| 985 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003", "file001"]) in fsList) |
| 986 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003", "file002"]) in fsList) |
| 987 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003", "file003"]) in fsList) |
| 988 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003", "link001"]) in fsList) |
| 989 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003", "link002"]) in fsList) |
| 990 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003", "cback.encrypt"]) in fsList) |
| 991 |
self.assertTrue(self.buildPath(["tree16", "dir004", "cback.encrypt"]) in fsList) |
| 992 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004"]) in fsList) |
| 993 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file001"]) in fsList) |
| 994 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file002"]) in fsList) |
| 995 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file003"]) in fsList) |
| 996 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file004"]) in fsList) |
| 997 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file005"]) in fsList) |
| 998 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file006"]) in fsList) |
| 999 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file007"]) in fsList) |
| 1000 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file008"]) in fsList) |
| 1001 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "link001"]) in fsList) |
| 1002 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "cback.store"]) in fsList) |
| 1003 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005"]) in fsList) |
| 1004 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file001"]) in fsList) |
| 1005 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file002"]) in fsList) |
| 1006 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file003"]) in fsList) |
| 1007 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file004"]) in fsList) |
| 1008 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file005"]) in fsList) |
| 1009 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file006"]) in fsList) |
| 1010 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file007"]) in fsList) |
| 1011 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file008"]) in fsList) |
| 1012 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "link001"]) in fsList) |
| 1013 |
self.assertTrue(self.buildPath(["tree16", "cback.collect"]) in fsList) |
| 1014 |
self.assertTrue(self.buildPath(["tree16", "cback.stage"]) in fsList) |
| 1015 |
self.assertTrue(self.buildPath(["tree16", "cback.store"]) in fsList) |
| 1016 |
_encryptDailyDir(dailyDir, "gpg", VALID_GPG_RECIPIENT, None, None) |
| 1017 |
fsList = FilesystemList() |
| 1018 |
fsList.addDirContents(dailyDir) |
| 1019 |
# since all links are to files, and the files all changed names, the links are invalid and disappear |
| 1020 |
self.assertEqual(102, len(fsList)) |
| 1021 |
self.assertTrue(self.buildPath(["tree16"]) in fsList) |
| 1022 |
self.assertTrue(self.buildPath(["tree16", "dir001"]) in fsList) |
| 1023 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001"]) in fsList) |
| 1024 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file001.gpg"]) in fsList) |
| 1025 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file002.gpg"]) in fsList) |
| 1026 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file003.gpg"]) in fsList) |
| 1027 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file004.gpg"]) in fsList) |
| 1028 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file005.gpg"]) in fsList) |
| 1029 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file006.gpg"]) in fsList) |
| 1030 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file007.gpg"]) in fsList) |
| 1031 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir001", "file008.gpg"]) in fsList) |
| 1032 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir002"]) in fsList) |
| 1033 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir002", "file001.gpg"]) in fsList) |
| 1034 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir002", "file002.gpg"]) in fsList) |
| 1035 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir002", "file003.gpg"]) in fsList) |
| 1036 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir002", "file004.gpg"]) in fsList) |
| 1037 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir003"]) in fsList) |
| 1038 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir003", "file001.gpg"]) in fsList) |
| 1039 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir003", "file002.gpg"]) in fsList) |
| 1040 |
self.assertTrue(self.buildPath(["tree16", "dir001", "dir003", "file003.gpg"]) in fsList) |
| 1041 |
self.assertTrue(self.buildPath(["tree16", "dir002"]) in fsList) |
| 1042 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir001"]) in fsList) |
| 1043 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir001", "cback.encrypt"]) in fsList) |
| 1044 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir001", "file001.gpg"]) in fsList) |
| 1045 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir001", "file002.gpg"]) in fsList) |
| 1046 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir001", "file003.gpg"]) in fsList) |
| 1047 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002"]) in fsList) |
| 1048 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "cback.encrypt"]) in fsList) |
| 1049 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "file001.gpg"]) in fsList) |
| 1050 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "file002.gpg"]) in fsList) |
| 1051 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "file003.gpg"]) in fsList) |
| 1052 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "file004.gpg"]) in fsList) |
| 1053 |
self.assertTrue(self.buildPath(["tree16", "dir002", "dir002", "file005.gpg"]) in fsList) |
| 1054 |
self.assertTrue(self.buildPath(["tree16", "dir003"]) in fsList) |
| 1055 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001"]) in fsList) |
| 1056 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file001.gpg"]) in fsList) |
| 1057 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file002.gpg"]) in fsList) |
| 1058 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file003.gpg"]) in fsList) |
| 1059 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file004.gpg"]) in fsList) |
| 1060 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file005.gpg"]) in fsList) |
| 1061 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file006.gpg"]) in fsList) |
| 1062 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file007.gpg"]) in fsList) |
| 1063 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "file008.gpg"]) in fsList) |
| 1064 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir001", "cback."]) in fsList) |
| 1065 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002"]) in fsList) |
| 1066 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002", "file001.gpg"]) in fsList) |
| 1067 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002", "file002.gpg"]) in fsList) |
| 1068 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002", "file003.gpg"]) in fsList) |
| 1069 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002", "file004.gpg"]) in fsList) |
| 1070 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir002", "cback.encrypt"]) in fsList) |
| 1071 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003"]) in fsList) |
| 1072 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "file001.gpg"]) in fsList) |
| 1073 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "file002.gpg"]) in fsList) |
| 1074 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "file003.gpg"]) in fsList) |
| 1075 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "cback.encrypt"]) in fsList) |
| 1076 |
self.assertTrue(self.buildPath(["tree16", "dir003", "dir003", "cback.store"]) in fsList) |
| 1077 |
self.assertTrue(self.buildPath(["tree16", "dir004"]) in fsList) |
| 1078 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001"]) in fsList) |
| 1079 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file001.gpg"]) in fsList) |
| 1080 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file002.gpg"]) in fsList) |
| 1081 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file003.gpg"]) in fsList) |
| 1082 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file004.gpg"]) in fsList) |
| 1083 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file005.gpg"]) in fsList) |
| 1084 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file006.gpg"]) in fsList) |
| 1085 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file007.gpg"]) in fsList) |
| 1086 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "file008.gpg"]) in fsList) |
| 1087 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "cback."]) in fsList) |
| 1088 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir001", "cback.collect"]) in fsList) |
| 1089 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002"]) in fsList) |
| 1090 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002", "file001.gpg"]) in fsList) |
| 1091 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002", "file002.gpg"]) in fsList) |
| 1092 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002", "file003.gpg"]) in fsList) |
| 1093 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002", "file004.gpg"]) in fsList) |
| 1094 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir002", "cback.encrypt"]) in fsList) |
| 1095 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003"]) in fsList) |
| 1096 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003", "file001.gpg"]) in fsList) |
| 1097 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003", "file002.gpg"]) in fsList) |
| 1098 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003", "file003.gpg"]) in fsList) |
| 1099 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir003", "cback.encrypt"]) in fsList) |
| 1100 |
self.assertTrue(self.buildPath(["tree16", "dir004", "cback.encrypt"]) in fsList) |
| 1101 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004"]) in fsList) |
| 1102 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file001.gpg"]) in fsList) |
| 1103 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file002.gpg"]) in fsList) |
| 1104 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file003.gpg"]) in fsList) |
| 1105 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file004.gpg"]) in fsList) |
| 1106 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file005.gpg"]) in fsList) |
| 1107 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file006.gpg"]) in fsList) |
| 1108 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file007.gpg"]) in fsList) |
| 1109 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "file008.gpg"]) in fsList) |
| 1110 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir004", "cback.store"]) in fsList) |
| 1111 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005"]) in fsList) |
| 1112 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file001.gpg"]) in fsList) |
| 1113 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file002.gpg"]) in fsList) |
| 1114 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file003.gpg"]) in fsList) |
| 1115 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file004.gpg"]) in fsList) |
| 1116 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file005.gpg"]) in fsList) |
| 1117 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file006.gpg"]) in fsList) |
| 1118 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file007.gpg"]) in fsList) |
| 1119 |
self.assertTrue(self.buildPath(["tree16", "dir004", "dir005", "file008.gpg"]) in fsList) |
| 1120 |
self.assertTrue(self.buildPath(["tree16", "cback.collect"]) in fsList) |
| 1121 |
self.assertTrue(self.buildPath(["tree16", "cback.stage"]) in fsList) |
| 1122 |
self.assertTrue(self.buildPath(["tree16", "cback.store"]) in fsList) |