1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 19:52:16 +00:00

Fix supysonic.utils.get_secret_key

This commit is contained in:
Alban Féron 2022-12-10 15:48:06 +01:00
parent 6bdee81e57
commit 64cf272887
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
4 changed files with 13 additions and 26 deletions

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2013-2020 Alban 'spl0k' Féron
# Copyright (C) 2013-2022 Alban 'spl0k' Féron
# 2017 Óscar García Amor
#
# Distributed under terms of the GNU AGPLv3 license.
@ -11,8 +11,6 @@ import random
import string
import uuid
from pony.orm import ObjectNotFound
from ..db import User

View File

@ -1,13 +1,12 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2019-2020 Alban 'spl0k' Féron
# Copyright (C) 2019-2022 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
from base64 import b64encode, b64decode
from os import urandom
from pony.orm import db_session, commit, ObjectNotFound
from supysonic.db import Meta
@ -19,16 +18,11 @@ def get_secret_key(keyname):
if keyname in __key_cache:
return __key_cache[keyname]
with db_session():
# Commit both at enter and exit. The metadb/db split (from supysonic.db)
# confuses Pony which can either error or hang when this method is called
commit()
try:
key = b64decode(Meta[keyname].value)
except ObjectNotFound:
key = urandom(128)
Meta(key=keyname, value=b64encode(key).decode())
commit()
try:
key = b64decode(Meta[keyname].value)
except Meta.DoesNotExist:
key = urandom(128)
Meta.create(key=keyname, value=b64encode(key).decode())
__key_cache[keyname] = key
return key

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2013-2018 Alban 'spl0k' Féron
# Copyright (C) 2013-2022 Alban 'spl0k' Féron
# 2018-2019 Carey 'pR0Ps' Metcalfe
# 2017 Óscar García Amor
#
@ -12,7 +12,6 @@ import mimetypes
from flask import Flask
from os import makedirs, path
from pony.orm import db_session
from .config import IniConfig
from .cache import Cache
@ -49,7 +48,6 @@ def create_application(config=None):
# Initialize database
init_database(app.config["BASE"]["database_uri"])
app.wsgi_app = db_session(app.wsgi_app)
# Insert unknown mimetypes
for k, v in app.config["MIMETYPES"].items():
@ -60,8 +58,8 @@ def create_application(config=None):
# Initialize Cache objects
# Max size is MB in the config file but Cache expects bytes
cache_dir = app.config["WEBAPP"]["cache_dir"]
max_size_cache = app.config["WEBAPP"]["cache_size"] * 1024 ** 2
max_size_transcodes = app.config["WEBAPP"]["transcode_cache_size"] * 1024 ** 2
max_size_cache = app.config["WEBAPP"]["cache_size"] * 1024**2
max_size_transcodes = app.config["WEBAPP"]["transcode_cache_size"] * 1024**2
app.cache = Cache(path.join(cache_dir, "cache"), max_size_cache)
app.transcode_cache = Cache(path.join(cache_dir, "transcodes"), max_size_transcodes)

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2017-2020 Alban 'spl0k' Féron
# Copyright (C) 2017-2022 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.
@ -13,8 +13,6 @@ import sys
import tempfile
import unittest
from pony.orm import db_session
from supysonic.db import init_database, release_database
from supysonic.config import DefaultConfig
from supysonic.managers.user import UserManager
@ -101,9 +99,8 @@ class TestBase(unittest.TestCase):
self.__app = create_application(self.config)
self.client = self.__app.test_client()
with db_session:
UserManager.add("alice", "Alic3", admin=True)
UserManager.add("bob", "B0b")
UserManager.add("alice", "Alic3", admin=True)
UserManager.add("bob", "B0b")
def _patch_client(self):
self.client.get = patch_method(self.client.get)