def test_tor2web_absence(self): """ This test checks: https://github.com/globaleaks/GlobaLeaks/issues/268 """ ### INITIALIZE BLOCK self.mockContext = helpers.MockDict().dummyContext self.mockReceiver = helpers.MockDict().dummyReceiver self.mockNode = helpers.MockDict().dummyNode self.createdContext = yield admin.create_context(self.mockContext) self.assertTrue(self.createdContext.has_key('id')) self.mockReceiver['contexts'] = [self.createdContext['id']] self.createdReceiver = yield admin.create_receiver(self.mockReceiver) self.assertTrue(self.createdReceiver.has_key('id')) self.createdNode = yield admin.update_node(self.mockNode) self.assertTrue(self.createdNode.has_key('version')) ### END OF THE INITIALIZE BLOCK # be sure of Tor2Web capability for attrname in Node.localized_strings: self.mockNode[attrname] = self.mockNode[attrname]['en'] self.createdNode = yield admin.update_node(self.mockNode) yield admin.import_memory_variables() self._load_defaults() self.mockSubmission = helpers.MockDict().dummySubmission self.mockSubmission['finalize'] = True self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0] self.mockSubmission['receivers'] = [self.createdReceiver['id']] self.mockSubmission['wb_fields'] = helpers.fill_random_fields( self.createdContext) self.createdSubmission = yield submission.create_submission( self.mockSubmission, finalize=True) created_rtip = yield delivery_sched.tip_creation() self.assertEqual(len(created_rtip), 1) yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0]) # adding funny configured variables self.templates['default_ETNT.txt'][ 'en'] += " %OttimoDireiOOOttimoDirei%" # with the event, we can finally call the format checks gentext = Templating().format_template( self.templates['default_ETNT.txt'], self.event) self.assertSubstring(self.createdContext['name'], gentext) self.assertSubstring(created_rtip[0], gentext) self.assertNotSubstring("%TipT2WURL%", gentext) # test against funny configured variables self.assertSubstring("%OttimoDireiOOOttimoDirei%", gentext)
def test_tor2web_absence(self): """ This test checks: https://github.com/globaleaks/GlobaLeaks/issues/268 """ ### INITIALIZE BLOCK self.mockContext = helpers.MockDict().dummyContext self.mockReceiver = helpers.MockDict().dummyReceiver self.mockNode = helpers.MockDict().dummyNode self.createdContext = yield admin.create_context(self.mockContext) self.assertTrue(self.createdContext.has_key('id')) self.mockReceiver['contexts'] = [ self.createdContext['id'] ] self.createdReceiver = yield admin.create_receiver(self.mockReceiver) self.assertTrue(self.createdReceiver.has_key('id')) self.createdNode = yield admin.update_node(self.mockNode) self.assertTrue(self.createdNode.has_key('version')) ### END OF THE INITIALIZE BLOCK # be sure of Tor2Web capability for attrname in Node.localized_strings: self.mockNode[attrname] = self.mockNode[attrname]['en'] self.createdNode = yield admin.update_node(self.mockNode) yield admin.import_memory_variables() self._load_defaults() self.mockSubmission = helpers.MockDict().dummySubmission self.mockSubmission['finalize'] = True self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0] self.mockSubmission['receivers'] = [ self.createdReceiver['id'] ] self.mockSubmission['wb_fields'] = helpers.fill_random_fields(self.createdContext) self.createdSubmission = yield submission.create_submission(self.mockSubmission, finalize=True) created_rtip = yield delivery_sched.tip_creation() self.assertEqual(len(created_rtip), 1) yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0]) # adding funny configured variables self.templates['default_ETNT.txt']['en'] += " %OttimoDireiOOOttimoDirei%" # with the event, we can finally call the format checks gentext = Templating().format_template(self.templates['default_ETNT.txt'], self.event) self.assertSubstring(self.createdContext['name'], gentext) self.assertSubstring(created_rtip[0], gentext) self.assertNotSubstring("%TipT2WURL%", gentext) # test against funny configured variables self.assertSubstring("%OttimoDireiOOOttimoDirei%", gentext)
def test_tor2web_absence(self): """ This test checks: https://github.com/globaleaks/GlobaLeaks/issues/268 """ yield self._initialize() # be sure of Tor2Web capability self.mockNode['tor2web_tip'] = False self.createdNode = yield admin.update_node(self.mockNode) yield admin.import_memory_variables() self._load_defaults() self.mockSubmission = MockDict().dummySubmission self.mockSubmission['finalize'] = True self.mockSubmission['context_gus'] = self.createdReceiver['contexts'][0] self.mockSubmission['receivers'] = [ self.createdReceiver['receiver_gus'] ] self.createdSubmission = yield submission.create_submission(self.mockSubmission, finalize=True) created_rtip = yield delivery_sched.tip_creation() self.assertEqual(len(created_rtip), 1) yield self._fill_event(u'tip', 'Tip', created_rtip[0]) # with the event, we can finally call the format checks gentext = MailNotification().format_template(self.Tip_notifi_template, self.event) self.assertSubstring(self.createdContext['name'], gentext) self.assertSubstring(created_rtip[0], gentext) self.assertNotSubstring("%TipT2WURL%", gentext)
def _initialize(self): self.mockContext = MockDict().dummyContext self.mockReceiver = MockDict().dummyReceiver self.mockNode = MockDict().dummyNode try: self.createdContext = yield admin.create_context(self.mockContext) self.assertTrue(self.createdContext.has_key('context_gus')) except Exception as excep: self.assertFalse(True) raise excep try: self.mockReceiver['contexts'] = [ self.createdContext['context_gus'] ] self.createdReceiver = yield admin.create_receiver(self.mockReceiver) self.assertTrue(self.createdReceiver.has_key('receiver_gus')) except Exception as excep: self.assertFalse(True) raise excep try: self.createdNode = yield admin.update_node(self.mockNode) self.assertTrue(self.createdNode.has_key('version')) except Exception as excep: self.assertFalse(True) raise excep
def update_node_properties(self): node_desc = yield admin.admin_serialize_node('en') self.assertEqual(node_desc['can_postpone_expiration'], False) node_desc['can_postpone_expiration'] = True stuff = u"³²¼½¬¼³²" for attrname in models.Node.localized_strings: node_desc[attrname] = stuff node_desc = yield admin.update_node(node_desc, True, 'en') self.assertEqual(node_desc['can_postpone_expiration'], True)
def test_002_get_ahmia_enabled(self): handler = self.request({}, role='admin') nodedict = helpers.MockDict().dummyNode nodedict['ahmia'] = True yield admin.update_node(nodedict) yield handler.get() self.assertTrue(isinstance(self.responses, list)) self.assertEqual(len(self.responses), 1) self._handler.validate_message(json.dumps(self.responses[0]), requests.ahmiaDesc)
def test_001_get_ahmia_disabled(self): handler = self.request({}, role='admin') nodedict = helpers.MockDict().dummyNode nodedict['ahmia'] = False yield admin.update_node(nodedict) yield handler.get() self.assertTrue(isinstance(self.responses, list)) self.assertEqual(len(self.responses), 0)
def test_get_ahmia_disabled(self): handler = self.request({}, role='admin') nodedict = helpers.MockDict().dummyNode nodedict['ahmia'] = False yield admin.update_node(nodedict, True, 'en') yield handler.get() self.assertTrue(isinstance(self.responses, list)) self.assertEqual(len(self.responses), 0)
def test_get_ahmia_enabled(self): handler = self.request({}, role='admin') nodedict = helpers.MockDict().dummyNode nodedict['ahmia'] = True yield admin.update_node(nodedict, True, 'en') yield handler.get() self.assertTrue(isinstance(self.responses, list)) self.assertEqual(len(self.responses), 1) self._handler.validate_message(json.dumps(self.responses[0]), requests.ahmiaDesc)
def update_node_properties(self): node_desc = yield admin.admin_serialize_node() self.assertEqual(node_desc['postpone_superpower'], False) node_desc['postpone_superpower'] = True stuff = u"³²¼½¬¼³²" for attrname in models.Node.localized_strings: node_desc[attrname] = stuff node_desc = yield admin.update_node(node_desc) self.assertEqual(node_desc['postpone_superpower'], True)
def test_default_template_keywords(self): self._load_defaults() ### INITIALIZE BLOCK self.mockContext = helpers.MockDict().dummyContext self.mockReceiver = helpers.MockDict().dummyReceiver self.mockNode = helpers.MockDict().dummyNode self.createdContext = yield admin.create_context(self.mockContext) self.assertTrue(self.createdContext.has_key('id')) self.mockReceiver['contexts'] = [self.createdContext['id']] self.createdReceiver = yield admin.create_receiver(self.mockReceiver) self.assertTrue(self.createdReceiver.has_key('id')) self.createdNode = yield admin.update_node(self.mockNode) self.assertTrue(self.createdNode.has_key('version')) ### END OF THE INITIALIZE BLOCK # THE REAL CONVERSION TEST START HERE: self.mockSubmission = helpers.MockDict().dummySubmission self.mockSubmission['finalize'] = True self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0] self.mockSubmission['receivers'] = [self.createdReceiver['id']] self.mockSubmission['wb_fields'] = helpers.fill_random_fields( self.createdContext) self.createdSubmission = yield submission.create_submission( self.mockSubmission, finalize=True) created_rtip = yield delivery_sched.tip_creation() self.assertEqual(len(created_rtip), 1) yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0]) # with the event, we can finally call the template filler gentext = Templating().format_template( self.templates['default_ETNT.txt'], self.event) self.assertSubstring(self.createdContext['name'], gentext) self.assertSubstring(created_rtip[0], gentext) self.assertSubstring(self.createdNode['public_site'], gentext)
def test_default_template_keywords(self): self._load_defaults() ### INITIALIZE BLOCK self.mockContext = helpers.MockDict().dummyContext self.mockReceiver = helpers.MockDict().dummyReceiver self.mockNode = helpers.MockDict().dummyNode self.createdContext = yield admin.create_context(self.mockContext) self.assertTrue(self.createdContext.has_key('id')) self.mockReceiver['contexts'] = [ self.createdContext['id'] ] self.createdReceiver = yield admin.create_receiver(self.mockReceiver) self.assertTrue(self.createdReceiver.has_key('id')) self.createdNode = yield admin.update_node(self.mockNode) self.assertTrue(self.createdNode.has_key('version')) ### END OF THE INITIALIZE BLOCK # THE REAL CONVERSION TEST START HERE: self.mockSubmission = helpers.MockDict().dummySubmission self.mockSubmission['finalize'] = True self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0] self.mockSubmission['receivers'] = [ self.createdReceiver['id'] ] self.mockSubmission['wb_fields'] = helpers.fill_random_fields(self.createdContext) self.createdSubmission = yield submission.create_submission(self.mockSubmission, finalize=True) created_rtip = yield delivery_sched.tip_creation() self.assertEqual(len(created_rtip), 1) yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0]) # with the event, we can finally call the template filler gentext = Templating().format_template(self.templates['default_ETNT.txt'], self.event) self.assertSubstring(self.createdContext['name'], gentext) self.assertSubstring(created_rtip[0], gentext) self.assertSubstring(self.createdNode['public_site'], gentext)
def update_node_properties(self): node_desc = yield admin.get_node() self.assertEqual(node_desc['postpone_superpower'], False) node_desc['postpone_superpower'] = True node_desc = yield admin.update_node(node_desc) self.assertEqual(node_desc['postpone_superpower'], True)
def test_keywords_conversion(self): self.templates = {} for t, keywords_list in templates_desc.iteritems(): self.templates[t] = "" for kwl in keywords_list: for keyword in kwl: self.templates[t] += " " + keyword + " / " ### INITIALIZE DATABASE self.mockContext = helpers.MockDict().dummyContext self.mockReceiver = helpers.MockDict().dummyReceiverGPG self.mockNode = helpers.MockDict().dummyNode self.createdContext = yield admin.create_context( self.mockContext, 'en') self.assertTrue('id' in self.createdContext) self.mockReceiver['contexts'] = [self.createdContext['id']] self.createdReceiver = yield admin.create_receiver( self.mockReceiver, 'en') self.assertTrue('id' in self.createdReceiver) self.createdNode = yield admin.update_node(self.mockNode, True, 'en') self.assertTrue('version' in self.createdNode) ### END OF THE INITIALIZE BLOCK # THE REAL CONVERSION TEST START HERE: self.mockSubmission = helpers.MockDict().dummySubmission self.mockSubmission['finalize'] = True self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0] self.mockSubmission['receivers'] = [self.createdReceiver['id']] self.mockSubmission['wb_fields'] = helpers.fill_random_fields( self.createdContext) self.createdSubmission = yield submission.create_submission( self.mockSubmission, True, 'en') created_rtip = yield delivery_sched.tip_creation() self.assertEqual(len(created_rtip), 1) # some doubt in the next two lines: is just to have a mock tip self.tip = dict(self.mockSubmission) self.tip['id'] = created_rtip[0] for template_name, template in self.templates.iteritems(): # look for appropriate event_type, event_trigger event_type = u'' event_trigger = '' for e_t, e_tri in supported_event_types.iteritems(): if template_name.startswith(e_t): event_type = e_t event_trigger = e_tri break if not event_type: # we've nothing to do not! continue yield self._fill_event_dict(event_type, event_trigger) # with the event, we can finally call the template filler gentext = Templating().format_template(template, self.event) if template_name != 'ping_mail_template' and template_name != 'ping_mail_title': self.assertSubstring(self.createdContext['name'], gentext) self.assertSubstring(self.createdNode['public_site'], gentext) self.assertSubstring(self.createdNode['hidden_service'], gentext)
def test_keywords_conversion(self): ### INITIALIZE BLOCK self.mockContext =helpers.MockDict().dummyContext self.mockReceiver = helpers.MockDict().dummyReceiver self.mockNode = helpers.MockDict().dummyNode self.createdContext = yield admin.create_context(self.mockContext) self.assertTrue(self.createdContext.has_key('id')) self.mockReceiver['contexts'] = [ self.createdContext['id'] ] self.createdReceiver = yield admin.create_receiver(self.mockReceiver) self.assertTrue(self.createdReceiver.has_key('id')) self.createdNode = yield admin.update_node(self.mockNode) self.assertTrue(self.createdNode.has_key('version')) ### END OF THE INITIALIZE BLOCK self.templates = {} for t in self.templates_list: self.templates[t] = { 'en': u"" } for k in notifTemplateTest.generic_keyword_list: self.templates[t]['en'] += " " + k for k in notifTemplateTest.tip_keyword_list: self.templates['default_ETNT.txt']['en'] += " " + k self.templates['default_PTNT.txt']['en'] += " " + k for k in notifTemplateTest.protected_keyword_list: self.templates['default_ETNT.txt']['en'] += " " + k for k in notifTemplateTest.comment_keyword_list: self.templates['default_ECNT.txt']['en'] += " " + k self.templates['default_PCNT.txt']['en'] += " " + k for k in notifTemplateTest.file_keyword_list: self.templates['default_EFNT.txt']['en'] += " " + k self.templates['default_PFNT.txt']['en'] += " " + k # THE REAL CONVERSION TEST START HERE: self.mockSubmission = helpers.MockDict().dummySubmission self.mockSubmission['finalize'] = True self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0] self.mockSubmission['receivers'] = [ self.createdReceiver['id'] ] self.mockSubmission['wb_fields'] = helpers.fill_random_fields(self.createdContext) self.createdSubmission = yield submission.create_submission(self.mockSubmission, finalize=True) created_rtip = yield delivery_sched.tip_creation() self.assertEqual(len(created_rtip), 1) yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0]) # with the event, we can finally call the template filler gentext = Templating().format_template(self.templates['default_ETNT.txt'], self.event) self.assertSubstring(self.createdContext['name'], gentext) self.assertSubstring(created_rtip[0], gentext) self.assertSubstring(self.createdNode['public_site'], gentext) self.assertSubstring(self.createdNode['hidden_service'], gentext) ## HERE ARE ADDED SOME CHECK self.assertSubstring("=================", gentext) # http://witchwind.wordpress.com/2013/12/15/piv-is-always-rape-ok/ # wtf has the internet in those days ? bwahahaah tip_num_test = Templating().format_template({'en': u'%TipNum%'}, self.event) new_id = self.event.trigger_info['id'].replace('1', '2') new_id.replace('3', '4') self.event.trigger_info['id'] = new_id.replace('5', '6') different_num = Templating().format_template({'en': u'%TipNum%'}, self.event) self.assertNotEqual(tip_num_test, different_num)
def test_keywords_conversion(self): self.templates = {} for t, keywords_list in templates_desc.iteritems(): self.templates[t] = "" for kwl in keywords_list: for keyword in kwl: self.templates[t] += " " + keyword + " / " ### INITIALIZE DATABASE self.mockContext =helpers.MockDict().dummyContext self.mockReceiver = helpers.MockDict().dummyReceiver self.mockNode = helpers.MockDict().dummyNode self.createdContext = yield admin.create_context(self.mockContext) self.assertTrue(self.createdContext.has_key('id')) self.mockReceiver['contexts'] = [ self.createdContext['id'] ] self.createdReceiver = yield admin.create_receiver(self.mockReceiver) self.assertTrue(self.createdReceiver.has_key('id')) self.createdNode = yield admin.update_node(self.mockNode) self.assertTrue(self.createdNode.has_key('version')) ### END OF THE INITIALIZE BLOCK # THE REAL CONVERSION TEST START HERE: self.mockSubmission = helpers.MockDict().dummySubmission self.mockSubmission['finalize'] = True self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0] self.mockSubmission['receivers'] = [ self.createdReceiver['id'] ] self.mockSubmission['wb_fields'] = helpers.fill_random_fields(self.createdContext) self.createdSubmission = yield submission.create_submission(self.mockSubmission, finalize=True) created_rtip = yield delivery_sched.tip_creation() self.assertEqual(len(created_rtip), 1) # some doubt in the next two lines: is just to have a mock tip self.tip = dict(self.mockSubmission) self.tip['id'] = created_rtip[0] for fname, template in self.templates.iteritems(): # look for appropriate event_type, event_trigger event_type = u'' event_trigger = '' for e_t, e_tri in supported_event_types.iteritems(): if fname.startswith(e_t): event_type = e_t event_trigger = e_tri break if not event_type: # we've nothing to do not! break yield self._fill_event_dict(event_type, event_trigger) # with the event, we can finally call the template filler gentext = Templating().format_template(template, self.event) self.assertSubstring(self.createdContext['name'], gentext) self.assertSubstring(self.createdNode['public_site'], gentext) self.assertSubstring(self.createdNode['hidden_service'], gentext)
def test_keywords_conversion(self): ### INITIALIZE BLOCK self.mockContext = helpers.MockDict().dummyContext self.mockReceiver = helpers.MockDict().dummyReceiver self.mockNode = helpers.MockDict().dummyNode self.createdContext = yield admin.create_context(self.mockContext) self.assertTrue(self.createdContext.has_key('id')) self.mockReceiver['contexts'] = [self.createdContext['id']] self.createdReceiver = yield admin.create_receiver(self.mockReceiver) self.assertTrue(self.createdReceiver.has_key('id')) self.createdNode = yield admin.update_node(self.mockNode) self.assertTrue(self.createdNode.has_key('version')) ### END OF THE INITIALIZE BLOCK self.templates = {} for t in self.templates_list: self.templates[t] = {'en': u""} for k in notifTemplateTest.generic_keyword_list: self.templates[t]['en'] += " " + k for k in notifTemplateTest.tip_keyword_list: self.templates['default_ETNT.txt']['en'] += " " + k self.templates['default_PTNT.txt']['en'] += " " + k for k in notifTemplateTest.protected_keyword_list: self.templates['default_ETNT.txt']['en'] += " " + k for k in notifTemplateTest.comment_keyword_list: self.templates['default_ECNT.txt']['en'] += " " + k self.templates['default_PCNT.txt']['en'] += " " + k for k in notifTemplateTest.file_keyword_list: self.templates['default_EFNT.txt']['en'] += " " + k self.templates['default_PFNT.txt']['en'] += " " + k # THE REAL CONVERSION TEST START HERE: self.mockSubmission = helpers.MockDict().dummySubmission self.mockSubmission['finalize'] = True self.mockSubmission['context_id'] = self.createdReceiver['contexts'][0] self.mockSubmission['receivers'] = [self.createdReceiver['id']] self.mockSubmission['wb_fields'] = helpers.fill_random_fields( self.createdContext) self.createdSubmission = yield submission.create_submission( self.mockSubmission, finalize=True) created_rtip = yield delivery_sched.tip_creation() self.assertEqual(len(created_rtip), 1) yield self._fill_event(u'encrypted_tip', 'Tip', created_rtip[0]) # with the event, we can finally call the template filler gentext = Templating().format_template( self.templates['default_ETNT.txt'], self.event) self.assertSubstring(self.createdContext['name'], gentext) self.assertSubstring(created_rtip[0], gentext) self.assertSubstring(self.createdNode['public_site'], gentext) self.assertSubstring(self.createdNode['hidden_service'], gentext) ## HERE ARE ADDED SOME CHECK self.assertSubstring("=================", gentext) # http://witchwind.wordpress.com/2013/12/15/piv-is-always-rape-ok/ # wtf has the internet in those days ? bwahahaah tip_num_test = Templating().format_template({'en': u'%TipNum%'}, self.event) new_id = self.event.trigger_info['id'].replace('1', '2') new_id.replace('3', '4') self.event.trigger_info['id'] = new_id.replace('5', '6') different_num = Templating().format_template({'en': u'%TipNum%'}, self.event) self.assertNotEqual(tip_num_test, different_num)