def _get_auth_api_key_name_selection(self):
     selection = []
     for section in serv_config.sections():
         if section.startswith("api_key_") and serv_config.has_option(
                 section, "key"):
             selection.append((section, section))
     return selection
 def _get_api_key_name(cls, auth_api_key):
     for section in serv_config.sections():
         if section.startswith("api_key_") and serv_config.has_option(
                 section, "key"):
             if tools.consteq(auth_api_key, serv_config.get(section,
                                                            "key")):
                 return section
     return None
Ejemplo n.º 3
0
 def setUp(self, *args, **kwargs):
     super(ShopinvaderRestCase, self).setUp(*args, **kwargs)
     self.backend = self.env.ref("shopinvader.backend_1")
     # To ensure multi-backend works correctly, we just have to create
     # a new one on the same company.
     self.backend_copy = self.env.ref("shopinvader.backend_2")
     self.api_key = "myApiKey"
     self.api_key2 = "myApiKey2"
     self.auth_api_key_name = self.AUTH_API_KEY_NAME
     self.auth_api_key_name2 = self.AUTH_API_KEY_NAME2
     if self.auth_api_key_name not in serv_config.sections():
         serv_config.add_section(self.auth_api_key_name)
         serv_config.set(self.auth_api_key_name, "user", "admin")
         serv_config.set(self.auth_api_key_name, "key", self.api_key)
     if self.auth_api_key_name2 not in serv_config.sections():
         serv_config.add_section(self.auth_api_key_name2)
         serv_config.set(self.auth_api_key_name2, "user", "admin")
         serv_config.set(self.auth_api_key_name2, "key", self.api_key2)
     self.backend.auth_api_key_name = self.auth_api_key_name2
Ejemplo n.º 4
0
 def setUp(self):
     super(CommonMixin, self).setUp()
     self.env = self.env(context={"lang": "en_US"})
     self.backend = self.env.ref("shopinvader.backend_1")
     self.backend.bind_all_product()
     self.shopinvader_session = {}
     self.api_key = "myApiKey"
     self.auth_api_key_name = self.AUTH_API_KEY_NAME
     if self.auth_api_key_name not in serv_config.sections():
         serv_config.add_section(self.auth_api_key_name)
         serv_config.set(self.auth_api_key_name, "user", "admin")
         serv_config.set(self.auth_api_key_name, "key", self.api_key)
     self.backend.auth_api_key_name = self.auth_api_key_name
Ejemplo n.º 5
0
 def setUpClass(cls):
     super(CommonCase, cls).setUpClass()
     cls.setUpComponent()
     cls.env = cls.env(context={"lang": "en_US"})
     cls.backend = cls.env.ref("shopinvader.backend_1")
     cls.backend.bind_all_product()
     cls.shopinvader_session = {}
     cls.api_key = "myApiKey"
     cls.auth_api_key_name = cls.AUTH_API_KEY_NAME
     if cls.auth_api_key_name not in serv_config.sections():
         serv_config.add_section(cls.auth_api_key_name)
         serv_config.set(cls.auth_api_key_name, "user", "admin")
         serv_config.set(cls.auth_api_key_name, "key", cls.api_key)
     cls.backend.auth_api_key_name = cls.auth_api_key_name
Ejemplo n.º 6
0
def migrate(cr, version):
    _logger.info("Create auth_api.key records from odoo config")
    with odoo.api.Environment.manage():
        env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
        for section in serv_config.sections():
            if section.startswith("api_key_") and serv_config.has_option(
                    section, "key"):
                login_name = serv_config.get(section, "user")
                name = section.replace("api_key_", "")
                key = "<set from server environment>"
                user = env["res.users"].search([("login", "=", login_name)])
                env["auth.api.key"].create({
                    "name": name,
                    "key": key,
                    "user_id": user.id
                })
                _logger.info("API Key record created for %s", section)
Ejemplo n.º 7
0
    def _retrieve_uid_from_api_key(self, api_key):
        if not self.env.user.has_group("base.group_system"):
            raise AccessError(_("User is not allowed"))

        for section in serv_config.sections():
            if section.startswith("api_key_") and serv_config.has_option(
                    section, "key"):
                if not consteq(api_key, serv_config.get(section, "key")):
                    continue

                login_name = serv_config.get(section, "user")
                uid = self.env["res.users"].search([("login", "=", login_name)
                                                    ]).id

                if not uid:
                    raise ValidationError(
                        _("No user found with login %s") % login_name)

                return uid
        return False
Ejemplo n.º 8
0
 def setUp(self):
     super(StockCommonCase, self).setUp()
     ref = self.env.ref
     self.shopinvader_backend = ref("shopinvader.backend_1")
     self.warehouse_1 = ref("stock.warehouse0")
     self.loc_1 = self.warehouse_1.lot_stock_id
     self.warehouse_2 = ref("stock.stock_warehouse_shop0")
     self.loc_2 = self.warehouse_2.lot_stock_id
     self.product = ref("product.product_product_4")
     self.shopinvader_backend.bind_all_product()
     self.index = self.env["se.index"].create({
         "name":
         "test-product-index",
         "backend_id":
         self.backend_specific.se_backend_id.id,
         "exporter_id":
         ref("shopinvader.ir_exp_shopinvader_variant").id,
         "lang_id":
         ref("base.lang_en").id,
         "model_id":
         ref("shopinvader.model_shopinvader_variant").id,
     })
     self.shopinvader_backend.write({
         "se_backend_id":
         self.backend_specific.se_backend_id.id,
         "warehouse_ids": [(6, 0, self.warehouse_1.ids)],
         "product_stock_field_id":
         ref("stock.field_product_product_qty_available").id,
     })
     self.loc_supplier = self.env.ref("stock.stock_location_suppliers")
     self.picking_type_in = self.env.ref("stock.picking_type_in")
     self.auth_api_key_name = self.AUTH_API_KEY_NAME
     self.api_key = "myApiKey"
     if self.auth_api_key_name not in serv_config.sections():
         serv_config.add_section(self.auth_api_key_name)
         serv_config.set(self.auth_api_key_name, "user", "admin")
         serv_config.set(self.auth_api_key_name, "key", self.api_key)
     self.shopinvader_backend.auth_api_key_name = self.auth_api_key_name
# Copyright 2017 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <*****@*****.**>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import unittest
from uuid import uuid4

import requests
from odoo.addons.server_environment import serv_config
from odoo.exceptions import MissingError
from odoo.tools import mute_logger

from .common import ShopinvaderRestCase


@unittest.skipIf(
    ShopinvaderRestCase.AUTH_API_KEY_NAME not in serv_config.sections(),
    "You must define an auth_api_key section '%s' into your configuration "
    "to run controller tests" % ShopinvaderRestCase.AUTH_API_KEY_NAME,
)
class ShopinvaderControllerCase(ShopinvaderRestCase):
    def setUp(self, *args, **kwargs):
        super(ShopinvaderControllerCase, self).setUp(*args, **kwargs)
        self.url = self.base_url + "/shopinvader/addresses"
        self.partner = self.env.ref("shopinvader.partner_1")
        self.address_1 = self.env.ref("shopinvader.partner_1_address_1")
        self.address_2 = self.env.ref("shopinvader.partner_1_address_2")

    def test_get_addresses_with_correct_api_key_and_partner(self):
        result = requests.get(
            self.url,
            headers={