Files @ 31f510a88584
Branch filter:

Location: kallithea/rhodecode/tests/models/test_license.py

Bradley M. Kuhn
Update minified YUI to version 2.9 built from Source.

yui.2.9.js used to be a minified version of YUI 2.9 until 5143b8df576c updated
it to something else and applied more aggresive minification. We stick to a
clean but minified version 2.9.

The license of YUI is BSD 3-clause, as described on
http://yuilibrary.com/license/ .

Since the minified version combines with GPLv3'd Javascript, it is only GPLv3'd
compliant to distribute this Object Code version with the Corresponding Source
(or offer therefor).

This yui.2.9.js is built from Source this way:
git clone https://github.com/yui/builder
git clone https://github.com/yui/yui2
cd yui2/
git checkout hudson-yui2-2800
ln -sf JumpToPageDropDown.js src/paginator/js/JumpToPageDropdown.js # work around inconsistent casing
rm -f tmp.js
for m in yahoo event dom connection animation dragdrop element datasource autocomplete container event-delegate json datatable paginator; do
rm -f build/$m/$m.js; ( cd src/$m && ant build deploybuild ) && sed -e 's,@VERSION@,2.9.0,g' -e 's,@BUILD@,2800,g' build/$m/$m.js >> tmp.js
done
java -jar ../builder/componentbuild/lib/yuicompressor/yuicompressor-2.4.4.jar tmp.js -o yui.2.9.js

The source is mirrored and available on https://kallithea-scm.org/repos/mirror .
from __future__ import with_statement

from rhodecode.tests import *
from rhodecode.tests.fixture import Fixture
from rhodecode.lib.compat import json
from rhodecode.model.license import LicenseModel

fixture = Fixture()

TEST_KEY = ''


class LicenseTest(BaseTestCase):

    def setUp(self):
        global TEST_KEY
        token = LicenseModel.generate_license_token()
        TEST_KEY = token

    def test_encryption_decryption(self):
        test_license = {
            'foo': 'baar',
            'signature': 'test'
        }
        enc = LicenseModel(key=TEST_KEY).encrypt(json.dumps(test_license))
        dec = json.loads(LicenseModel(key=TEST_KEY).decrypt(enc))
        self.assertEqual(test_license, dec)

    def test_signature(self):
        enc_with_key = '1234567890123456'
        test_license = {
            'foo': 'baar',
            'signature': None
        }
        test_license['signature'] = LicenseModel(key=TEST_KEY)\
            .generate_signature(test_license, enc_with_key)

        enc = LicenseModel(key=TEST_KEY).encrypt(json.dumps(test_license))
        signature = LicenseModel(key=TEST_KEY).verify(enc, enc_with_key)

        del test_license['signature']
        self.assertEqual(test_license, signature)

    def test_signature_mismatch(self):
        enc_with_key = '1234567890123456'
        test_license = {
            'foo': 'baar',
            'signature': 'cnashs62tdsbcsaaisuda6215sagc'
        }

        enc = LicenseModel(key=TEST_KEY).encrypt(json.dumps(test_license))

        self.assertRaises(TypeError,
            lambda: LicenseModel(key=TEST_KEY).verify(enc, enc_with_key))

    def test_generate_license_token(self):
        token = LicenseModel.generate_license_token()
        self.assertEqual(4, len(token.split('-')))

    def test_get_license_info(self):
        info = LicenseModel.get_license_info('', '')
        self.assertEqual(info, {})

    def test_get_license_info_default(self):
        info = LicenseModel.get_license_info('', '', fill_defaults=True)
        self.assertEqual(info['users'], 20)
        self.assertEqual(info['valid_till'], 1421884937.512214)
        self.assertEqual(info['email'], 'support@rhodecode.com')