45
45
# Test that parsing a simple top level channels.json file produces the
46
46
# expected set of channels. The Nexus 7 daily images have a device
47
47
# specific keyring.
48
channels = get_channels('channels_01.json')
48
channels = get_channels('channel.channels_01.json')
49
49
self.assertEqual(channels.daily.devices.nexus7.index,
50
50
'/daily/nexus7/index.json')
51
51
self.assertEqual(channels.daily.devices.nexus7.keyring.path,
62
62
def test_getattr_failure(self):
63
63
# Test the getattr syntax on an unknown channel or device combination.
64
channels = get_channels('channels_01.json')
64
channels = get_channels('channel.channels_01.json')
65
65
self.assertRaises(AttributeError, getattr, channels, 'bleeding')
66
66
self.assertRaises(AttributeError, getattr, channels.stable, 'nexus3')
68
68
def test_daily_proposed(self):
69
69
# The channel name has a dash in it.
70
channels = get_channels('channels_07.json')
70
channels = get_channels('channel.channels_02.json')
71
71
self.assertEqual(channels['daily-proposed'].devices.grouper.index,
72
72
'/daily-proposed/grouper/index.json')
74
74
def test_bad_getitem(self):
75
75
# Trying to get a channel via getitem which doesn't exist.
76
channels = get_channels('channels_07.json')
76
channels = get_channels('channel.channels_02.json')
77
77
self.assertRaises(KeyError, getitem, channels, 'daily-testing')
79
79
def test_channel_version(self):
80
80
# The channel name has a dot in it.
81
channels = get_channels('channels_08.json')
81
channels = get_channels('channel.channels_03.json')
82
82
self.assertEqual(channels['13.10'].devices.grouper.index,
83
83
'/13.10/grouper/index.json')
85
85
def test_channel_version_proposed(self):
86
86
# The channel name has both a dot and a dash in it.
87
channels = get_channels('channels_08.json')
87
channels = get_channels('channel.channels_03.json')
88
88
self.assertEqual(channels['14.04-proposed'].devices.grouper.index,
89
89
'/14.04-proposed/grouper/index.json')
103
103
self._serverdir = self._stack.enter_context(temporary_directory())
104
104
self._stack.push(make_http_server(
105
105
self._serverdir, 8943, 'cert.pem', 'key.pem'))
106
copy('channels_01.json', self._serverdir, 'channels.json')
106
copy('channel.channels_01.json', self._serverdir, 'channels.json')
107
107
self._channels_path = os.path.join(
108
108
self._serverdir, 'channels.json')
124
124
'/daily/nexus7/device-keyring.tar.xz.asc')
127
def test_load_channel_bad_signature(self, ini_file):
127
def test_load_channel_bad_signature(self):
128
128
# We get an error if the signature on the channels.json file is bad.
129
129
sign(self._channels_path, 'spare.gpg')
148
148
self.assertRaises(SignatureError, next, self._state)
151
def test_load_channel_bad_signature_gets_fixed(self, ini_file):
151
def test_load_channel_bad_signature_gets_fixed(self, config_d):
152
152
# Like above, but the second download of the image signing key results
153
153
# in a properly signed channels.json file.
154
154
sign(self._channels_path, 'spare.gpg')
165
165
os.path.join(self._serverdir, 'gpg',
166
166
'image-signing.tar.xz'))
167
167
# This will succeed by grabbing a new image-signing key.
168
config = Configuration(ini_file)
168
config = Configuration(config_d)
169
169
with open(config.gpg.image_signing, 'rb') as fp:
170
170
checksum = hashlib.md5(fp.read()).digest()
171
171
next(self._state)
180
180
'/daily/nexus7/device-keyring.tar.xz.asc')
183
def test_load_channel_blacklisted_signature(self, ini_file):
183
def test_load_channel_blacklisted_signature(self, config_d):
184
184
# We get an error if the signature on the channels.json file is good
185
185
# but the key is blacklisted.
186
186
sign(self._channels_path, 'image-signing.gpg')
193
193
# cause the state machine to try to download a new image signing key,
194
194
# so let's put the cached one up on the server. This will still be
195
195
# backlisted though.
196
config = Configuration(ini_file)
196
config = Configuration(config_d)
197
197
key_path = os.path.join(self._serverdir, 'gpg', 'image-signing.tar.xz')
198
198
shutil.copy(config.gpg.image_signing, key_path)
199
199
shutil.copy(config.gpg.image_signing + '.asc', key_path + '.asc')
215
215
self._stack = ExitStack()
217
217
self._serverdir = self._stack.enter_context(temporary_directory())
218
copy('channels_01.json', self._serverdir, 'channels.json')
218
copy('channel.channels_01.json', self._serverdir, 'channels.json')
219
219
sign(os.path.join(self._serverdir, 'channels.json'),
220
220
'image-signing.gpg')
242
242
"""LP: #1221841 introduces a new format to channels.json."""
243
243
def test_channels(self):
244
244
# We can parse new-style channels.json files.
245
channels = get_channels('channels_09.json')
245
channels = get_channels('channel.channels_04.json')
246
246
self.assertEqual(channels.daily.alias, 'saucy')
247
247
self.assertEqual(channels.daily.devices.grouper.index,
248
248
'/daily/grouper/index.json')
263
263
def test_hidden_defaults_to_false(self):
264
264
# If a channel does not have a hidden field, it defaults to false.
265
channels = get_channels('channels_09.json')
265
channels = get_channels('channel.channels_04.json')
266
266
self.assertFalse(channels.daily.hidden)
268
268
def test_getattr_failure(self):
269
269
# Test the getattr syntax on an unknown channel or device combination.
270
channels = get_channels('channels_09.json')
270
channels = get_channels('channel.channels_04.json')
271
271
self.assertRaises(AttributeError, getattr, channels, 'bleeding')
272
272
self.assertRaises(
273
273
AttributeError, getattr, channels.daily.devices, 'nexus3')
275
275
def test_daily_proposed(self):
276
276
# The channel name has a dash in it.
277
channels = get_channels('channels_09.json')
277
channels = get_channels('channel.channels_04.json')
278
278
self.assertEqual(channels['saucy-proposed'].devices.grouper.index,
279
279
'/saucy-proposed/grouper/index.json')
281
281
def test_bad_getitem(self):
282
282
# Trying to get a channel via getitem which doesn't exist.
283
channels = get_channels('channels_09.json')
283
channels = get_channels('channel.channels_04.json')
284
284
self.assertRaises(KeyError, getitem, channels, 'daily-testing')