def test_updatecheck_positive_critical_on_other_channel(self): app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome') platform = PlatformFactory.create(name='win') channel = ChannelFactory.create(name='stable') channel2 = ChannelFactory.create(name='alpha') first_version = VersionFactory.create( app=app, platform=platform, channel=channel, version='13.0.782.110', file=SimpleUploadedFile('./chrome_installer_first.exe', b'_' * 23963192), file_size=23963192) first_version.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' first_version.save() critical_version = VersionFactory.create( is_critical=True, app=app, platform=platform, channel=channel2, version='13.0.782.111', file=SimpleUploadedFile('./chrome_installer_critical.exe', b'_' * 23963192), file_size=23963192) critical_version.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' critical_version.save() last_version = VersionFactory.create( app=app, platform=platform, channel=channel, version='13.0.782.112', file=SimpleUploadedFile('./chrome_installer.exe', b'_' * 23963192), file_size=23963192) last_version.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' last_version.save() Action.objects.create( version=last_version, arguments='--do-not-launch-chrome', event=EVENT_DICT_CHOICES['install'], run='chrome_installer.exe' ) Action.objects.create( version=last_version, event=EVENT_DICT_CHOICES['postinstall'], other=dict( version='13.0.782.112', onsuccess='exitsilentlyonlaunchcmd', ) ) response = self.client.post(reverse('update'), fixtures.request_update_check, content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertXmlDocument(response.content) self.assertXmlEquivalentOutputs(response.content, fixtures.response_update_check_positive)
def setUp(self): self.app = ApplicationFactory(name='TestApp') self.channel = ChannelFactory(name='alpha') self.stable_channel = ChannelFactory(name='stable') self.win_v1 = VersionFactory(version='10.0.0.0', app=self.app, channel=self.channel) self.win_v2 = VersionFactory(version='42.0.1.0', app=self.app, channel=self.channel) self.win_stable_v = VersionFactory(version='23.0.0.0', app=self.app, channel=self.stable_channel) self.win_disabled_v = VersionFactory(version='55.0.2.0', app=self.app, channel=self.channel, is_enabled=False) self.mac_v1 = SparkleVersionFactory(short_version='10.0.0.0', version='0.0', app=self.app, channel=self.channel) self.mac_v2 = SparkleVersionFactory(short_version='42.0.1.0', version='1.0', app=self.app, channel=self.channel) self.mac_stable_v = SparkleVersionFactory(short_version='23.0.0.0', version='0.0', app=self.app, channel=self.stable_channel) self.mac_disabled_v = SparkleVersionFactory(short_version='55.0.2.0', version='2.0', app=self.app, channel=self.channel, is_enabled=False) self.exp_res = { self.app.name: { "win": { self.channel.name: { "url": self.win_v2.file_absolute_url, "version": self.win_v2.version }, self.stable_channel.name: { "url": self.win_stable_v.file_absolute_url, "version": self.win_stable_v.version } }, "mac": { self.channel.name: { "url": self.mac_v2.file_absolute_url, "version": self.mac_v2.short_version }, self.stable_channel.name: { "url": self.mac_stable_v.file_absolute_url, "version": self.mac_stable_v.short_version } } } }
def test_data(self): app = ApplicationFactory.create(id='{430FD4D0-B729-4F61-AA34-91526481799D}', name='chrome') platform = PlatformFactory.create(name='win') channel = ChannelFactory.create(name='stable') obj = VersionFactory.create( app=app, platform=platform, channel=channel, version='13.0.782.112', file=SimpleUploadedFile('./chrome_installer.exe', b'_' * 23963192), file_size=23963192) obj.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' obj.save() Data.objects.create( app=app, name=NAME_DATA_DICT_CHOICES['install'], index='verboselogging', value='app-specific values here') Data.objects.create( app=app, name=NAME_DATA_DICT_CHOICES['untrusted']) response = self.client.post(reverse('update'), fixtures.request_data, content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertXmlDocument(response.content) self.assertXmlEquivalentOutputs(response.content, fixtures.response_data)
def test_data(self): app = ApplicationFactory.create( id='{430FD4D0-B729-4F61-AA34-91526481799D}', name='chrome') platform = PlatformFactory.create(name='win') channel = ChannelFactory.create(name='stable') obj = VersionFactory.create(app=app, platform=platform, channel=channel, version='13.0.782.112', file=SimpleUploadedFile( './chrome_installer.exe', b'_' * 23963192), file_size=23963192) obj.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' obj.save() Data.objects.create(app=app, name=NAME_DATA_DICT_CHOICES['install'], index='verboselogging', value='app-specific values here') Data.objects.create(app=app, name=NAME_DATA_DICT_CHOICES['untrusted']) response = self.client.post(reverse('update'), fixtures.request_data, content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertXmlDocument(response.content) self.assertXmlEquivalentOutputs(response.content, fixtures.response_data)
def test_sparkle(self): app = ApplicationFactory.create( id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome') channel = ChannelFactory.create(name='stable') obj = SparkleVersionFactory.create(app=app, channel=channel, version='782.112', short_version='13.0.782.112', minimum_system_version='10.14.4', file=SimpleUploadedFile( './chrome.dmg', b'_' * 23963192), file_size=23963192) obj.save() response = self.client.get(reverse('sparkle_appcast', args=(app.name, channel.name)), HTTP_HOST='example.com') self.assertEqual(response.status_code, 200) self.assertXmlDocument(response.content) self.assertXmlEquivalentOutputs( response.content, fixtures.response_sparkle_with_minimum_system_version)
class SparkleVersionFactory(factory.DjangoModelFactory): class Meta: model = 'sparkle.SparkleVersion' app = factory.lazy_attribute(lambda x: ApplicationFactory()) channel = factory.lazy_attribute(lambda x: ChannelFactory()) version = '2062.124' short_version = '37.0.2062.124'
def test_sparkle_critical(self): app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome') channel = ChannelFactory.create(name='stable') first_version = SparkleVersionFactory.create( app=app, channel=channel, version='782.110', short_version='13.0.782.110', file=SimpleUploadedFile('./chrome1.dmg', b'_' * 23963192), file_size=23963192) first_version.save() first_crit_version = SparkleVersionFactory.create( app=app, channel=channel, version='782.111', short_version='13.0.782.111', is_critical=True, file=SimpleUploadedFile('./chrome2.dmg', b'_' * 23963192), file_size=23963192) first_crit_version.save() last_version = SparkleVersionFactory.create( app=app, channel=channel, version='782.112', short_version='13.0.782.112', file=SimpleUploadedFile('./chrome3.dmg', b'_' * 23963192), file_size=23963192) last_version.save() second_crit_version = SparkleVersionFactory.create( app=app, channel=channel, version='782.113', short_version='13.0.782.113', is_critical=True, file=SimpleUploadedFile('./chrome4.dmg', b'_' * 23963192), file_size=23963192) second_crit_version.save() response = self.client.get("%s?appVersionShort=13.0.782.110" % reverse('sparkle_appcast', args=(app.name, channel.name)), HTTP_HOST='example.com') self.assertEqual(response.status_code, 200) self.assertXmlDocument(response.content) self.assertXmlEquivalentOutputs(response.content, fixtures.first_crit_response_sparkle) response = self.client.get("%s?appVersionShort=13.0.782.111" % reverse('sparkle_appcast', args=(app.name, channel.name)), HTTP_HOST='example.com') self.assertEqual(response.status_code, 200) self.assertXmlDocument(response.content) self.assertXmlEquivalentOutputs(response.content, fixtures.second_crit_response_sparkle)
class SparkleVersionFactory(factory.DjangoModelFactory): class Meta: model = 'sparkle.SparkleVersion' app = factory.lazy_attribute(lambda x: ApplicationFactory()) channel = factory.lazy_attribute(lambda x: ChannelFactory()) version = '2062.124' short_version = '37.0.2062.124' file = factory.django.FileField(filename='the_file.dat') file_size = 123
def test_userid_counting(self): now = datetime.utcnow() userid = '{D0BBD725-742D-44ae-8D46-0231E881D58E}' user_id = get_id(userid) appid1 = '{430FD4D0-B729-4F61-AA34-91526481799D}' appid2 = '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}' request_events = DayEvents('request', now.year, now.month, now.day) app1_events = DayEvents('request:%s' % appid1, now.year, now.month, now.day) app2_events = DayEvents('request:%s' % appid2, now.year, now.month, now.day) self.assertEqual(len(request_events), 0) self.assertEqual(len(app1_events), 0) self.assertEqual(len(app2_events), 0) app = ApplicationFactory.create( id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome') platform = PlatformFactory.create(name='win') channel = ChannelFactory.create(name='stable') obj = VersionFactory.create(app=app, platform=platform, channel=channel, version='13.0.782.112', file=SimpleUploadedFile( './chrome_installer.exe', b'_' * 23963192)) obj.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' obj.save() Action.objects.create(version=obj, arguments='--do-not-launch-chrome', event=EVENT_DICT_CHOICES['install'], run='chrome_installer.exe') Action.objects.create(version=obj, event=EVENT_DICT_CHOICES['postinstall'], other=dict( version='13.0.782.112', onsuccess='exitsilentlyonlaunchcmd', )) self.client.post(reverse('update'), fixtures.request_update_check, content_type='text/xml') self.assertEqual(len(request_events), 1) self.assertEqual(len(app1_events), 1) self.assertEqual(len(app2_events), 1) self.assertTrue(user_id in request_events) self.assertTrue(user_id in app1_events) self.assertTrue(user_id in app2_events)
def test_create(self): data = dict( app=ApplicationFactory.create().id, channel=ChannelFactory.create().id, version='1.2.3.4', file=SimpleUploadedFile("chrome.exe", b'content'), ) response = self.client.post(self.url, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) version = SparkleVersion.objects.get(id=response.data['id']) self.assertEqual(response.data, self.serializer(version).data) self.assertEqual(version.file_size, len(b'content'))
def test_userid_counting(self): now = datetime.utcnow() userid = '{D0BBD725-742D-44ae-8D46-0231E881D58E}' user_id = get_id(userid) appid1 = '{430FD4D0-B729-4F61-AA34-91526481799D}' appid2 = '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}' request_events = DayEvents('request', now.year, now.month, now.day) app1_events = DayEvents('request:%s' % appid1, now.year, now.month, now.day) app2_events = DayEvents('request:%s' % appid2, now.year, now.month, now.day) self.assertEqual(len(request_events), 0) self.assertEqual(len(app1_events), 0) self.assertEqual(len(app2_events), 0) app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome') platform = PlatformFactory.create(name='win') channel = ChannelFactory.create(name='stable') obj = VersionFactory.create( app=app, platform=platform, channel=channel, version='13.0.782.112', file=SimpleUploadedFile('./chrome_installer.exe', b'_' * 23963192)) obj.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' obj.save() Action.objects.create( version=obj, arguments='--do-not-launch-chrome', event=EVENT_DICT_CHOICES['install'], run='chrome_installer.exe' ) Action.objects.create( version=obj, event=EVENT_DICT_CHOICES['postinstall'], other=dict( version='13.0.782.112', onsuccess='exitsilentlyonlaunchcmd', ) ) self.client.post(reverse('update'), fixtures.request_update_check, content_type='text/xml') self.assertEqual(len(request_events), 1) self.assertEqual(len(app1_events), 1) self.assertEqual(len(app2_events), 1) self.assertTrue(user_id in request_events) self.assertTrue(user_id in app1_events) self.assertTrue(user_id in app2_events)
def test_updatecheck_positive_critical(self): app = ApplicationFactory.create( id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome') platform = PlatformFactory.create(name='win') channel = ChannelFactory.create(name='stable') first_version = VersionFactory.create( app=app, platform=platform, channel=channel, version='13.0.782.110', file=SimpleUploadedFile('./chrome_installer_first.exe', b'_' * 23963192), file_size=23963192) first_version.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' first_version.save() critical_version = VersionFactory.create( is_critical=True, app=app, platform=platform, channel=channel, version='13.0.782.111', file=SimpleUploadedFile('./chrome_installer_critical.exe', b'_' * 23963192), file_size=23963192) critical_version.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' critical_version.save() last_version = VersionFactory.create(app=app, platform=platform, channel=channel, version='13.0.782.112', file=SimpleUploadedFile( './chrome_installer.exe', b'_' * 23963192), file_size=23963192) last_version.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' last_version.save() response = self.client.post(reverse('update'), fixtures.request_update_check, content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertXmlDocument(response.content) self.assertXmlEquivalentOutputs( response.content, fixtures.response_update_check_postitive_critical)
def test_update(self): data = dict( app=ApplicationFactory.create().id, channel=ChannelFactory.create().id, version='3.4', file=SimpleUploadedFile("chrome.exe", b'content'), ) response = self.client.post(reverse(self.url), data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) obj_id = response.data['id'] version = SparkleVersion.objects.get(id=obj_id) self.assertEqual(version.version, '3.4') url = reverse(self.url_detail, kwargs=dict(pk=obj_id)) response = self.client.patch(url, dict(version='3.5')) self.assertEqual(response.status_code, status.HTTP_200_OK) version = SparkleVersion.objects.get(id=obj_id) self.assertEqual(version.version, '3.5')
def test_public_sparkle_update(self): ChannelFactory._meta.database = 'root' channel_name = 'test' channel = ChannelFactory(name=channel_name) app_name = 'SparrowTestApp' ApplicationFactory._meta.database = 'root' app = ApplicationFactory(name=app_name) file = SimpleUploadedFile("test.dmg", b"content") SparkleVersionFactory._meta.database = 'root' SparkleVersionFactory.create(channel=channel, app=app, file=file) url = '%s%s' % (self.live_server_url, reverse('sparkle_appcast', kwargs=dict(app_name=app_name, channel=channel_name)) ) # replace by reverse resp = requests.get(url) root = objectify.fromstring(resp.content) self.assertTrue(app_name in str(root.channel.item.title))
def test_updatecheck_positive_critical(self): app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome') platform = PlatformFactory.create(name='win') channel = ChannelFactory.create(name='stable') first_version = VersionFactory.create( app=app, platform=platform, channel=channel, version='13.0.782.110', file=SimpleUploadedFile('./chrome_installer_first.exe', b'_' * 23963192), file_size=23963192) first_version.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' first_version.save() critical_version = VersionFactory.create( is_critical=True, app=app, platform=platform, channel=channel, version='13.0.782.111', file=SimpleUploadedFile('./chrome_installer_critical.exe', b'_' * 23963192), file_size=23963192) critical_version.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' critical_version.save() last_version = VersionFactory.create( app=app, platform=platform, channel=channel, version='13.0.782.112', file=SimpleUploadedFile('./chrome_installer.exe', b'_' * 23963192), file_size=23963192) last_version.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' last_version.save() response = self.client.post(reverse('update'), fixtures.request_update_check, content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertXmlDocument(response.content) self.assertXmlEquivalentOutputs(response.content, fixtures.response_update_check_postitive_critical)
def test_sparkle(self): app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome') channel = ChannelFactory.create(name='stable') obj = SparkleVersionFactory.create( app=app, channel=channel, version='782.112', short_version='13.0.782.112', file=SimpleUploadedFile('./chrome.dmg', b'_' * 23963192), file_size=23963192) obj.save() response = self.client.get(reverse('sparkle_appcast', args=(app.name, channel.name)), HTTP_HOST='example.com') self.assertEqual(response.status_code, 200) self.assertXmlDocument(response.content) self.assertXmlEquivalentOutputs(response.content, fixtures.response_sparkle)
def test_sparkle_with_dsa_signature(self): app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C9C}', name='chrome_dsa') channel = ChannelFactory.create(name='stable') obj = SparkleVersionFactory.create( app=app, channel=channel, version='782.112', short_version='13.0.782.112', dsa_signature='MCwCFCdoW13VBGJWIfIklKxQVyetgxE7AhQTVuY9uQT0KOV1UEk21epBsGZMPg==', file=SimpleUploadedFile('./chrome.dmg', b'_' * 23963192), file_size=23963192) obj.save() response = self.client.get(reverse('sparkle_appcast', args=(app.name, channel.name)), HTTP_HOST='example.com') self.assertEqual(response.status_code, 200) self.assertXmlDocument(response.content) self.assertXmlEquivalentOutputs(fixtures.response_sparkle_with_dsa, response.content)
def test_update(self): data = dict( app=ApplicationFactory.create().id, platform=PlatformFactory.create().id, channel=ChannelFactory.create().id, version='1.2.3.4', file=SimpleUploadedFile("chrome.exe", b'content'), is_enabled=False, ) response = self.client.post(reverse(self.url), data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) obj_id = response.data['id'] version = Version.objects.get(id=obj_id) self.assertEqual(version.file_size, len(b'content')) self.assertFalse(version.is_enabled) url = reverse(self.url_detail, kwargs=dict(pk=obj_id)) response = self.client.patch(url, dict(is_enabled=True)) self.assertEqual(response.status_code, status.HTTP_200_OK) version = Version.objects.get(id=obj_id) self.assertEqual(version.file_size, len(b'content')) self.assertTrue(version.is_enabled)
def test_factory(self): channel = ChannelFactory.create() self.assertTrue(Channel.objects.get(id=channel.id))
def test_serializer(self): data = dict(name='stable') channel = ChannelFactory(**data) self.assertDictEqual( ChannelSerializer(channel).data, dict(id=channel.pk, **data))