def key_rotation(): kr = KeyRotation.query.first() form = KeyRotationForm() oxauth_servers = [server for server in Server.query] if request.method == "GET" and kr is not None: form.interval.data = kr.interval form.type.data = kr.type form.oxeleven_url.data = kr.oxeleven_url form.inum_appliance.data = kr.inum_appliance if form.validate_on_submit(): if not kr: kr = KeyRotation() kr.interval = form.interval.data kr.type = form.type.data kr.oxeleven_url = form.oxeleven_url.data kr.inum_appliance = form.inum_appliance.data kr.oxeleven_token_key = generate_random_key() kr.oxeleven_token_iv = generate_random_iv() kr.oxeleven_token = encrypt_text( b"{}".format(form.oxeleven_token.data), kr.oxeleven_token_key, kr.oxeleven_token_iv, ) db.session.add(kr) db.session.commit() # rotate the keys immediately rotate_pub_keys.delay() return redirect(url_for("key_rotation")) return render_template("key_rotation.html", form=form, rotation=kr, oxauth_servers=oxauth_servers)
def test_gen_rand_key_uses_os_urandom(self, mockur): mockur.return_value = 'asdf' generate_random_key(10) mockur.assert_called_once_with(10)
def test_gen_rand_key_returns_a_default_length_of_32(self): assert len(generate_random_key()) == 32
def test_gen_rand_key_returns_random_string_of_requested_length(self): key = generate_random_key(10) assert len(key) == 10