Beispiel #1
0
    def setUpClass(cls):
        cls.bot_id = str(uuid4())
        cls.skill_id = str(uuid4())

        cls._test_id_factory = ConversationIdFactoryForTest()

        cls._claims_identity = ClaimsIdentity({}, False)

        cls._claims_identity.claims[AuthenticationConstants.AUDIENCE_CLAIM] = cls.bot_id
        cls._claims_identity.claims[AuthenticationConstants.APP_ID_CLAIM] = cls.skill_id
        cls._claims_identity.claims[
            AuthenticationConstants.SERVICE_URL_CLAIM
        ] = "http://testbot.com/api/messages"
        cls._conversation_reference = ConversationReference(
            conversation=ConversationAccount(id=str(uuid4())),
            service_url="http://testbot.com/api/messages",
        )
        activity = Activity.create_message_activity()
        activity.apply_conversation_reference(cls._conversation_reference)
        skill = BotFrameworkSkill(
            app_id=cls.skill_id,
            id="skill",
            skill_endpoint="http://testbot.com/api/messages",
        )
        cls._options = SkillConversationIdFactoryOptions(
            from_bot_oauth_scope=cls.bot_id,
            from_bot_id=cls.bot_id,
            activity=activity,
            bot_framework_skill=skill,
        )
Beispiel #2
0
    async def test_post_activity_with_originating_audience(self):
        conversation_id = str(uuid4())
        conversation_id_factory = SimpleConversationIdFactory(conversation_id)
        test_activity = MessageFactory.text("some message")
        test_activity.conversation = ConversationAccount()
        skill = BotFrameworkSkill(
            id="SomeSkill",
            app_id="",
            skill_endpoint="https://someskill.com/api/messages",
        )

        async def _mock_post_content(
            to_url: str,
            token: str,  # pylint: disable=unused-argument
            activity: Activity,
        ) -> (int, object):
            nonlocal self
            self.assertEqual(skill.skill_endpoint, to_url)
            # Assert that the activity being sent has what we expect.
            self.assertEqual(conversation_id, activity.conversation.id)
            self.assertEqual("https://parentbot.com/api/messages",
                             activity.service_url)

            # Create mock response.
            return 200, None

        sut = await self._create_http_client_with_mock_handler(
            _mock_post_content, conversation_id_factory)

        result = await sut.post_activity_to_skill(
            "",
            skill,
            "https://parentbot.com/api/messages",
            test_activity,
            "someOriginatingAudience",
        )

        # Assert factory options
        self.assertEqual("",
                         conversation_id_factory.creation_options.from_bot_id)
        self.assertEqual(
            "someOriginatingAudience",
            conversation_id_factory.creation_options.from_bot_oauth_scope,
        )
        self.assertEqual(test_activity,
                         conversation_id_factory.creation_options.activity)
        self.assertEqual(
            skill,
            conversation_id_factory.creation_options.bot_framework_skill)

        # Assert result
        self.assertIsInstance(result, InvokeResponse)
        self.assertEqual(200, result.status)
Beispiel #3
0
 def _create_skill_dialog_options(self,
                                  conversation_state: ConversationState,
                                  skill_client: BotFrameworkClient):
     return SkillDialogOptions(
         bot_id=str(uuid.uuid4()),
         skill_host_endpoint="http://test.contoso.com/skill/messages",
         conversation_id_factory=SimpleConversationIdFactory(),
         conversation_state=conversation_state,
         skill_client=skill_client,
         skill=BotFrameworkSkill(
             app_id=str(uuid.uuid4()),
             skill_endpoint="http://testskill.contoso.com/api/messages",
         ),
     )
Beispiel #4
0
class DefaultConfig:
    """
    Bot Configuration
    """

    SERVER_URL = ""  # pylint: disable=invalid-name
    PORT = os.getenv("Port", "37420")
    APP_ID = os.getenv("MicrosoftAppId")
    APP_PASSWORD = os.getenv("MicrosoftAppPassword")
    CONNECTION_NAME = os.getenv("ConnectionName")
    SSO_CONNECTION_NAME = os.getenv("SsoConnectionName")
    CHANNEL_SERVICE = os.getenv("ChannelService")
    SKILL_HOST_ENDPOINT = os.getenv("SkillHostEndpoint")
    # If ALLOWED_CALLERS is empty, any bot can call this Skill.
    # Add MicrosoftAppIds to restrict callers to only those specified.
    # Example:
    #   os.getenv("AllowedCallers", ["54d3bb6a-3b6d-4ccd-bbfd-cad5c72fb53a", "3851a47b-53ed-4d29-b878-6e941da61e98"])
    ALLOWED_CALLERS = os.getenv("AllowedCallers")
    ECHO_SKILL_INFO = BotFrameworkSkill(
        id=os.getenv("EchoSkillInfo_id"),
        app_id=os.getenv("EchoSkillInfo_appId"),
        skill_endpoint=os.getenv("EchoSkillInfo_skillEndpoint"),
    )
class SkillConfiguration:
    SKILL_HOST_ENDPOINT = DefaultConfig.SKILL_HOST_ENDPOINT
    SKILLS: Dict[str, BotFrameworkSkill] = {
        skill["id"]: BotFrameworkSkill(**skill)
        for skill in DefaultConfig.SKILLS
    }
Beispiel #6
0
    async def test_post_activity_using_invoke_response(self):
        for is_gov in [True, False]:
            with self.subTest(is_government=is_gov):
                # pylint: disable=undefined-variable
                # pylint: disable=cell-var-from-loop
                conversation_id = str(uuid4())
                conversation_id_factory = SimpleConversationIdFactory(
                    conversation_id)
                test_activity = MessageFactory.text("some message")
                test_activity.conversation = ConversationAccount()
                expected_oauth_scope = (
                    AuthenticationConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE)
                mock_channel_provider: ChannelProvider = Mock(
                    spec=ChannelProvider)

                def is_government_mock():
                    nonlocal expected_oauth_scope
                    if is_government:
                        expected_oauth_scope = (
                            GovernmentConstants.TO_CHANNEL_FROM_BOT_OAUTH_SCOPE
                        )

                    return is_government

                mock_channel_provider.is_government = Mock(
                    side_effect=is_government_mock)

                skill = BotFrameworkSkill(
                    id="SomeSkill",
                    app_id="",
                    skill_endpoint="https://someskill.com/api/messages",
                )

                async def _mock_post_content(
                    to_url: str,
                    token: str,  # pylint: disable=unused-argument
                    activity: Activity,
                ) -> (int, object):
                    nonlocal self

                    self.assertEqual(skill.skill_endpoint, to_url)
                    # Assert that the activity being sent has what we expect.
                    self.assertEqual(conversation_id, activity.conversation.id)
                    self.assertEqual("https://parentbot.com/api/messages",
                                     activity.service_url)

                    # Create mock response.
                    return 200, None

                sut = await self._create_http_client_with_mock_handler(
                    _mock_post_content, conversation_id_factory)
                result = await sut.post_activity_to_skill(
                    "", skill, "https://parentbot.com/api/messages",
                    test_activity)

                # Assert factory options
                self.assertEqual(
                    "", conversation_id_factory.creation_options.from_bot_id)
                self.assertEqual(
                    expected_oauth_scope,
                    conversation_id_factory.creation_options.
                    from_bot_oauth_scope,
                )
                self.assertEqual(
                    test_activity,
                    conversation_id_factory.creation_options.activity)
                self.assertEqual(
                    skill, conversation_id_factory.creation_options.
                    bot_framework_skill)

                # Assert result
                self.assertIsInstance(result, InvokeResponse)
                self.assertEqual(200, result.status)
 def _build_bot_framework_skill(self) -> BotFrameworkSkill:
     return BotFrameworkSkill(
         app_id=self._application_id,
         id=self.SKILL_ID,
         skill_endpoint=self.SERVICE_URL,
     )