def test_session_store_ignores_new_values_in_session_data(self):
        session_data = SessionData(
            tx_id="tx_id",
            schema_name="some_schema_name",
            period_str="period_str",
            language_code=None,
            launch_language_code=None,
            survey_url=None,
            ru_name="ru_name",
            ru_ref="ru_ref",
            response_id="response_id",
            questionnaire_id="questionnaire_id",
            case_id="case_id",
        )

        session_data.additional_value = "some cool new value you do not know about yet"

        with self._app.test_request_context():
            self.session_store.create(
                eq_session_id="eq_session_id",
                user_id="test",
                session_data=self.session_data,
                expires_at=self.expires_at,
            ).save()

            session_store = SessionStore("user_ik", "pepper", "eq_session_id")

            self.assertFalse(
                hasattr(session_store.session_data, "additional_value"))
    def test_session_store_stores_none_for_trading_as_if_not_present(self):
        session_data = SessionData(
            tx_id="tx_id",
            schema_name="some_schema_name",
            period_str="period_str",
            language_code=None,
            launch_language_code=None,
            survey_url=None,
            ru_name="ru_name",
            ru_ref="ru_ref",
            response_id="response_id",
            questionnaire_id="questionnaire_id",
            case_id="case_id",
        )
        with self._app.test_request_context():
            self.session_store.create(
                eq_session_id="eq_session_id",
                user_id="test",
                session_data=session_data,
                expires_at=self.expires_at,
            ).save()

            session_store = SessionStore("user_ik", "pepper", "eq_session_id")

            self.assertIsNone(session_store.session_data.trad_as)
    def setUp(self):
        super().setUp()
        self.user_id = "user_id"
        self.user_ik = "user_ik"
        self.pepper = "pepper"
        self.session_id = "session_id"
        self.expires_at = datetime.utcnow() + timedelta(seconds=3)
        self.session_data = SessionData(
            tx_id="tx_id",
            schema_name="some_schema_name",
            period_str="period_str",
            language_code=None,
            launch_language_code=None,
            survey_url=None,
            ru_name="ru_name",
            response_id="response_id",
            questionnaire_id="questionnaire_id",
            ru_ref="ru_ref",
            trad_as="trading_as_name",
            case_id="case_id",
        )

        # pylint: disable=protected-access
        self.key = storage_encryption.StorageEncryption._generate_key(
            self.user_id, self.user_ik, self.pepper)
コード例 #4
0
    def _load(self) -> None:
        logger.debug("finding eq_session_id in database",
                     eq_session_id=self.eq_session_id)
        self._eq_session: Optional[EQSession] = current_app.eq["storage"].get(
            EQSession, self.eq_session_id)  # type: ignore

        if self._eq_session and self._eq_session.session_data:
            self.user_id = self._eq_session.user_id

            encrypted_session_data = self._eq_session.session_data
            session_data_as_bytes = StorageEncryption(
                self.user_id, self.user_ik,
                self.pepper).decrypt_data(encrypted_session_data)

            session_data_as_str = session_data_as_bytes.decode()
            # for backwards compatibility
            # session data used to be base64 encoded before encryption
            try:
                session_data_as_str = base64url_decode(
                    session_data_as_str).decode()
            except ValueError:
                pass

            self.session_data = json_loads(
                session_data_as_str, object_hook=lambda d: SessionData(**d))

            logger.debug(
                "found matching eq_session for eq_session_id in database",
                session_id=self._eq_session.eq_session_id,
                user_id=self._eq_session.user_id,
            )
        else:
            logger.debug("eq_session_id not found in database",
                         eq_session_id=self.eq_session_id)
def fake_session_data():
    return SessionData(
        tx_id="tx_id",
        schema_name="some_schema_name",
        language_code=None,
        launch_language_code=None,
        survey_url=None,
        ru_ref="ru_ref",
        response_id="response_id",
        case_id="case_id",
        period_str=None,
        ru_name=None,
    )
コード例 #6
0
def session_data_feedback():
    return SessionData(
        tx_id=tx_id,
        schema_name=schema_name,
        response_id=response_id,
        period_str=period_str,
        language_code=language_code,
        launch_language_code=None,
        survey_url=None,
        ru_name=ru_name,
        ru_ref=ru_ref,
        case_id=case_id,
        feedback_count=feedback_count,
    )
コード例 #7
0
def session_data():
    return SessionData(
        tx_id="123",
        schema_name="some_schema_name",
        display_address="68 Abingdon Road, Goathill",
        period_str=None,
        language_code="cy",
        launch_language_code="en",
        survey_url=None,
        ru_name=None,
        ru_ref=None,
        submitted_at=datetime.now(timezone.utc).isoformat(),
        response_id="321",
        case_id="789",
    )
コード例 #8
0
 def setUp(self):
     super().setUp()
     self.session_data = SessionData(
         tx_id="tx_id",
         schema_name="schema_name",
         response_id="response_id",
         period_str="period_str",
         language_code="cy",
         launch_language_code="en",
         survey_url=None,
         ru_name="ru_name",
         ru_ref="ru_ref",
         case_id="0123456789000000",
     )
     self.session_store = SessionStore("user_ik", "pepper", "eq_session_id")
     self.expires_at = datetime.now(tzutc()) + timedelta(seconds=5)
コード例 #9
0
 def setUp(self):
     super().setUp()
     self._app.permanent_session_lifetime = timedelta(seconds=1)
     self.session_store = SessionStore("user_ik", "pepper")
     self.expires_at = datetime.utcnow() + timedelta(seconds=3)
     self.session_data = SessionData(
         tx_id="tx_id",
         schema_name="some_schema_name",
         period_str="period_str",
         language_code=None,
         launch_language_code=None,
         survey_url=None,
         ru_name="ru_name",
         ru_ref="ru_ref",
         response_id="response_id",
         case_id="case_id",
     )
コード例 #10
0
def _create_session_data_from_metadata(metadata):
    """
    Creates a SessionData object from metadata
    :param metadata: metadata parsed from jwt token
    """
    session_data = SessionData(
        tx_id=metadata.get("tx_id"),
        schema_name=metadata.get("schema_name"),
        period_str=metadata.get("period_str"),
        language_code=metadata.get("language_code"),
        launch_language_code=metadata.get("language_code"),
        survey_url=metadata.get("survey_url"),
        ru_name=metadata.get("ru_name"),
        ru_ref=metadata.get("ru_ref"),
        response_id=metadata.get("response_id"),
        case_id=metadata["case_id"],
        case_ref=metadata.get("case_ref"),
        trad_as=metadata.get("trad_as"),
        account_service_url=metadata.get("account_service_url"),
        account_service_log_out_url=metadata.get("account_service_log_out_url"),
    )
    return session_data
コード例 #11
0
    def _load(self):
        logger.debug("finding eq_session_id in database",
                     eq_session_id=self.eq_session_id)

        self._eq_session = current_app.eq["ephemeral_storage"].get(
            EQSession, self.eq_session_id)

        if self._eq_session:

            self.user_id = self._eq_session.user_id

            if self._eq_session.session_data:
                encrypted_session_data = self._eq_session.session_data
                session_data = StorageEncryption(
                    self.user_id, self.user_ik,
                    self.pepper).decrypt_data(encrypted_session_data)

                session_data = session_data.decode()
                # for backwards compatibility
                # session data used to be base64 encoded before encryption
                try:
                    session_data = base64url_decode(session_data).decode()
                except ValueError:
                    pass

                self.session_data = json.loads(
                    session_data, object_hook=lambda d: SessionData(**d))

            logger.debug(
                "found matching eq_session for eq_session_id in database",
                session_id=self._eq_session.eq_session_id,
                user_id=self._eq_session.user_id,
            )
        else:
            logger.debug("eq_session_id not found in database",
                         eq_session_id=self.eq_session_id)

        return self._eq_session