def post_entry_add(request):

    engine = CryptoEngine(master_key=request.user.password)

    e = None
    attributes = set(['title', 'password', 'category'])
    if attributes <= set(request.POST.keys()):

        e = Entry(title=request.POST['title'],
                  password=request.POST['password'])

        for k, v in request.POST.items():
            if k == 'username':
                e.username = v
            elif k == 'url':
                e.url = v
            elif k == 'comment':
                e.comment = v
            elif k == 'expires':
                # date formated: m/d/Y
                e.expires = datetime.datetime.strptime(v, "%m/%d/%Y").date()
            elif k == 'category':
                c = Category.objects.filter(id=int(v))
                if len(c) == 0:
                    return HttpResponse(0)
                else:
                    e.category_id = int(v)
        try:
            e.save()
            return HttpResponse(1)
        except:
            return HttpResponse(0)
    else:
        return HttpResponse(0)
def post_entry_add(request):

    engine = CryptoEngine(master_key=request.user.password)

    e = None
    attributes = set(['title', 'password', 'category'])
    if attributes <= set(request.POST.keys()):

        e = Entry(title=request.POST['title'],
                  password=request.POST['password'])

        for k, v in request.POST.items():
            if k == 'username':
                e.username = v
            elif k == 'url':
                e.url = v
            elif k == 'comment':
                e.comment = v
            elif k == 'expires':
                # date formated: m/d/Y
                e.expires = datetime.datetime.strptime(v, "%m/%d/%Y").date()
            elif k == 'category':
                c = Category.objects.filter(id=int(v))
                if len(c) == 0:
                    return HttpResponse(0)
                else:
                    e.category_id = int(v)
        try:
            e.save()
            return HttpResponse(1)
        except:
            return HttpResponse(0)
    else:
        return HttpResponse(0)
    def setUp(self):
        e = Entry(title='Twitter', username='******', url='twitter.com',
                  password='******', comment='no comment')
        c = Category(title='Internet', parent=None)

        self.entry = e
        self.category = c

        c.save()
        e.category = c
        e.save()
Beispiel #4
0
    def setUp(self):
        e = Entry(title='Twitter',
                  username='******',
                  url='twitter.com',
                  password='******',
                  comment='no comment')
        c = Category(title='Internet', parent=None)

        self.entry = e
        self.category = c

        c.save()
        e.category = c
        e.save()
    def test_create_entry(self):

        e = Entry.objects.filter(title=self.entry.title)
        e = e[0]
        self.assertEquals(e.expires, None)
        self.assertEquals(e.date, self.now)

        # Entry without category
        e2 = Entry(title='Test', password='******')
        try:
            e2.save()
        except:
            pass
        else:
            self.fail('Should not save an entry without category...')
Beispiel #6
0
    def test_create_entry(self):

        e = Entry.objects.filter(title=self.entry.title)
        e = e[0]
        self.assertEquals(e.expires, None)
        self.assertEquals(e.date, self.now)

        # Entry without category
        e2 = Entry(title='Test', password='******')
        try:
            e2.save()
        except:
            pass
        else:
            self.fail('Should not save an entry without category...')
    def test_save_entry_with_encrypted_key(self):

        c = Category(title='Internet')
        c.save()

        for i, password in enumerate(self.texts):

            password_after_encryption = self.engine.encrypt(password)
            title = 'My Twitter Account: ' + str(i)
            e = Entry(title=title, username='******',
                      url='twitter.com', password=password_after_encryption,
                      comment='no comment')
            e.category = c
            e.save()

            # Fetches the saved entry
            f = Entry.objects.filter(title=title)[0]
            password_decrypted = self.engine.decrypt(f.password)

            self.assertEquals(password_after_encryption, f.password)
            self.assertEquals(password_decrypted, password)
            f.delete()
Beispiel #8
0
    def test_save_entry_with_encrypted_key(self):

        c = Category(title='Internet')
        c.save()

        for i, password in enumerate(self.texts):

            password_after_encryption = self.engine.encrypt(password)
            title = 'My Twitter Account: ' + str(i)
            e = Entry(title=title,
                      username='******',
                      url='twitter.com',
                      password=password_after_encryption,
                      comment='no comment')
            e.category = c
            e.save()

            # Fetches the saved entry
            f = Entry.objects.filter(title=title)[0]
            password_decrypted = self.engine.decrypt(f.password)

            self.assertEquals(password_after_encryption, f.password)
            self.assertEquals(password_decrypted, password)
            f.delete()