Example #1
0
    def __init__(self, connection_name: str):
        super(GcpDialog, self).__init__(GcpDialog.__name__, connection_name)

        self.gclient = GcpClient()
        self.data = GcpDialogData()

        self.add_dialog(
            OAuthPrompt(
                "GcpAuthPrompt",
                OAuthPromptSettings(
                    connection_name=connection_name,
                    text="Please Sign In",
                    title="Sign In",
                    timeout=300000,
                ),
            )
        )
        self.add_dialog(
            WaterfallDialog(
                "GcpDialog",
                [
                    self.get_token_step,
                    self.choose_all_or_specific_project,
                    self.choose_specific_project_step,
                    self.list_running_instances_step,
                ],
            )
        )

        self.initial_dialog_id = "GcpDialog"
    def __init__(
        self, connection_name: str
    ):
        super(MainDialog, self).__init__(MainDialog.__name__, connection_name)

        self.add_dialog(
            OAuthPrompt(
                OAuthPrompt.__name__,
                OAuthPromptSettings(
                    connection_name=connection_name,
                    text="Please Sign In",
                    title="Sign In",
                    timeout=300000
                )
            )
        )

        self.add_dialog(ConfirmPrompt(ConfirmPrompt.__name__))

        self.add_dialog(
            WaterfallDialog(
                "WFDialog", [
                    self.prompt_step,
                    self.login_step,
                    self.display_token_phase1,
                    self.display_token_phase2
                ]
            )
        )

        self.initial_dialog_id = "WFDialog"
Example #3
0
    def __init__(self, connection_name: str):
        super(MainDialog, self).__init__(MainDialog.__name__, connection_name)

        self.add_dialog(
            OAuthPrompt(
                OAuthPrompt.__name__,
                OAuthPromptSettings(
                    connection_name=connection_name,
                    text="Please Sign In",
                    title="Sign In",
                    timeout=300000,
                ),
            ))

        self.add_dialog(TextPrompt(TextPrompt.__name__))
        self.add_dialog(ConfirmPrompt(ConfirmPrompt.__name__))

        self.add_dialog(
            WaterfallDialog(
                "WFDialog",
                [
                    self.prompt_step,
                    self.login_step,
                    self.command_step,
                    self.process_step,
                ],
            ))

        self.initial_dialog_id = "WFDialog"
Example #4
0
    def __init__(self, connection_name: str):
        super(AzureDialog, self).__init__(AzureDialog.__name__,
                                          connection_name)

        self.azclient = AzureClient()
        self.data = AzureDialogData()

        self.add_dialog(
            OAuthPrompt(
                "AzureAuthPrompt",
                OAuthPromptSettings(
                    connection_name=connection_name,
                    text="Please Sign In",
                    title="Sign In",
                    timeout=300000,
                ),
            ))
        self.add_dialog(ChoicePrompt(ChoicePrompt.__name__))
        self.add_dialog(
            WaterfallDialog(
                "AzureDialog",
                [
                    self.get_token_step,
                    self.choose_subscription_step,
                    self.list_running_vms_step,
                ],
            ))

        self.initial_dialog_id = "AzureDialog"
    def __init__(self, configuration: DefaultConfig):
        super().__init__(AuthDialog.__name__)

        self.connection_name = configuration.CONNECTION_NAME

        self.add_dialog(ConfirmPrompt(ConfirmPrompt.__name__))
        self.add_dialog(
            OAuthPrompt(
                OAuthPrompt.__name__,
                OAuthPromptSettings(
                    connection_name=self.connection_name,
                    text=
                    f"Please Sign In to connection: '{self.connection_name}'",
                    title="Sign In",
                    timeout=
                    300000,  # User has 5 minutes to login (1000 * 60 * 5)
                ),
            ))

        self.add_dialog(
            WaterfallDialog(
                WaterfallDialog.__name__,
                [
                    self.prompt_step,
                    self.login_step,
                    self.display_token,
                ],
            ))

        # The initial child Dialog to run.
        self.initial_dialog_id = WaterfallDialog.__name__
Example #6
0
    async def test_should_call_oauth_prompt(self):
        connection_name = "myConnection"
        token = "abc123"

        async def callback_handler(turn_context: TurnContext):
            dialog_context = await dialogs.create_context(turn_context)

            results = await dialog_context.continue_dialog()
            if results.status == DialogTurnStatus.Empty:
                await dialog_context.prompt("prompt", PromptOptions())
            elif results.status == DialogTurnStatus.Complete:
                if results.result.token:
                    await turn_context.send_activity("Logged in.")
                else:
                    await turn_context.send_activity("Failed")

            await convo_state.save_changes(turn_context)

        # Initialize TestAdapter.
        adapter = TestAdapter(callback_handler)

        # Create ConversationState with MemoryStorage and register the state as middleware.
        convo_state = ConversationState(MemoryStorage())

        # Create a DialogState property, DialogSet and AttachmentPrompt.
        dialog_state = convo_state.create_property("dialogState")
        dialogs = DialogSet(dialog_state)
        dialogs.add(
            OAuthPrompt(
                "prompt",
                OAuthPromptSettings(connection_name, "Login", None, 300000)))

        async def inspector(activity: Activity, description: str = None):  # pylint: disable=unused-argument

            self.assertTrue(len(activity.attachments) == 1)
            self.assertTrue(activity.attachments[0].content_type ==
                            CardFactory.content_types.oauth_card)

            # send a mock EventActivity back to the bot with the token
            adapter.add_user_token(connection_name, activity.channel_id,
                                   activity.recipient.id, token)

            event_activity = create_reply(activity)
            event_activity.type = ActivityTypes.event
            event_activity.from_property, event_activity.recipient = (
                event_activity.recipient,
                event_activity.from_property,
            )
            event_activity.name = "tokens/response"
            event_activity.value = TokenResponse(
                connection_name=connection_name, token=token)

            context = TurnContext(adapter, event_activity)
            await callback_handler(context)

        step1 = await adapter.send("Hello")
        step2 = await step1.assert_reply(inspector)
        await step2.assert_reply("Logged in.")
Example #7
0
    async def test_should_end_oauth_prompt_on_invalid_message_when_end_on_invalid_message(
        self, ):
        connection_name = "myConnection"
        token = "abc123"
        magic_code = "888999"

        async def exec_test(turn_context: TurnContext):
            dialog_context = await dialogs.create_context(turn_context)

            results = await dialog_context.continue_dialog()

            if results.status == DialogTurnStatus.Empty:
                await dialog_context.prompt("prompt", PromptOptions())
            elif results.status == DialogTurnStatus.Complete:
                if results.result and results.result.token:
                    await turn_context.send_activity("Failed")

                else:
                    await turn_context.send_activity("Ended")

            await convo_state.save_changes(turn_context)

        # Initialize TestAdapter.
        adapter = TestAdapter(exec_test)

        # Create ConversationState with MemoryStorage and register the state as middleware.
        convo_state = ConversationState(MemoryStorage())

        # Create a DialogState property, DialogSet and AttachmentPrompt.
        dialog_state = convo_state.create_property("dialog_state")
        dialogs = DialogSet(dialog_state)
        dialogs.add(
            OAuthPrompt(
                "prompt",
                OAuthPromptSettings(connection_name, "Login", None, 300000,
                                    None, True),
            ))

        def inspector(activity: Activity, description: str = None):  # pylint: disable=unused-argument
            assert len(activity.attachments) == 1
            assert (activity.attachments[0].content_type ==
                    CardFactory.content_types.oauth_card)

            # send a mock EventActivity back to the bot with the token
            adapter.add_user_token(
                connection_name,
                activity.channel_id,
                activity.recipient.id,
                token,
                magic_code,
            )

        step1 = await adapter.send("Hello")
        step2 = await step1.assert_reply(inspector)
        step3 = await step2.send("test invalid message")
        await step3.assert_reply("Ended")
    async def test_oauth_prompt_doesnt_detect_code_in_begin_dialog(self):
        connection_name = "myConnection"
        token = "abc123"
        magic_code = "888999"

        async def exec_test(turn_context: TurnContext):
            # Add a magic code to the adapter preemptively so that we can test if the message that triggers
            # BeginDialogAsync uses magic code detection
            adapter.add_user_token(
                connection_name,
                turn_context.activity.channel_id,
                turn_context.activity.from_property.id,
                token,
                magic_code,
            )

            dialog_context = await dialogs.create_context(turn_context)

            results = await dialog_context.continue_dialog()
            if results.status == DialogTurnStatus.Empty:

                # If magicCode is detected when prompting, this will end the dialog and return the token in tokenResult
                token_result = await dialog_context.prompt("prompt", PromptOptions())
                if isinstance(token_result.result, TokenResponse):
                    self.assertTrue(False)  # pylint: disable=redundant-unittest-assert

            await convo_state.save_changes(turn_context)

        # Initialize TestAdapter.
        adapter = TestAdapter(exec_test)

        # Create ConversationState with MemoryStorage and register the state as middleware.
        convo_state = ConversationState(MemoryStorage())

        # Create a DialogState property, DialogSet and AttachmentPrompt.
        dialog_state = convo_state.create_property("dialog_state")
        dialogs = DialogSet(dialog_state)
        dialogs.add(
            OAuthPrompt(
                "prompt", OAuthPromptSettings(connection_name, "Login", None, 300000)
            )
        )

        def inspector(activity: Activity, description: str = None):  # pylint: disable=unused-argument
            assert len(activity.attachments) == 1
            assert (
                activity.attachments[0].content_type
                == CardFactory.content_types.oauth_card
            )

        step1 = await adapter.send(magic_code)
        await step1.assert_reply(inspector)
    async def test_should_call_oauth_prompt_with_code(self):
        connection_name = "myConnection"
        token = "abc123"
        magic_code = "888999"

        async def exec_test(turn_context: TurnContext):
            dc = await dialogs.create_context(turn_context)

            results = await dc.continue_dialog()
            if results.status == DialogTurnStatus.Empty:
                await dc.prompt('prompt', PromptOptions())
            elif results.status == DialogTurnStatus.Complete:
                if results.result.token:
                    await turn_context.send_activity('Logged in.')

                else:
                    await turn_context.send_activity('Failed')

            await convo_state.save_changes(turn_context)

        # Initialize TestAdapter.
        adapter = TestAdapter(exec_test)

        # Create ConversationState with MemoryStorage and register the state as middleware.
        convo_state = ConversationState(MemoryStorage())

        # Create a DialogState property, DialogSet and AttachmentPrompt.
        dialog_state = convo_state.create_property('dialog_state')
        dialogs = DialogSet(dialog_state)
        dialogs.add(
            OAuthPrompt(
                'prompt',
                OAuthPromptSettings(connection_name, 'Login', None, 300000)))

        def inspector(activity: Activity, description: str = None):
            assert (len(activity.attachments) == 1)
            assert (activity.attachments[0].content_type ==
                    CardFactory.content_types.oauth_card)

            # send a mock EventActivity back to the bot with the token
            adapter.add_user_token(connection_name, activity.channel_id,
                                   activity.recipient.id, token, magic_code)

        step1 = await adapter.send('Hello')
        step2 = await step1.assert_reply(inspector)
        step3 = await step2.send(magic_code)
        await step3.assert_reply('Logged in.')
    async def test_should_add_accepting_input_hint_oauth_prompt(self):
        connection_name = "myConnection"
        called = False

        async def callback_handler(turn_context: TurnContext):
            nonlocal called
            dialog_context = await dialogs.create_context(turn_context)

            await dialog_context.continue_dialog()
            await dialog_context.prompt(
                "prompt", PromptOptions(prompt=Activity(), retry_prompt=Activity())
            )

            self.assertTrue(
                dialog_context.active_dialog.state["options"].prompt.input_hint
                == InputHints.accepting_input
            )
            self.assertTrue(
                dialog_context.active_dialog.state["options"].retry_prompt.input_hint
                == InputHints.accepting_input
            )

            await convo_state.save_changes(turn_context)
            called = True

        # Initialize TestAdapter.
        adapter = TestAdapter(callback_handler)

        # Create ConversationState with MemoryStorage and register the state as middleware.
        convo_state = ConversationState(MemoryStorage())

        # Create a DialogState property, DialogSet and AttachmentPrompt.
        dialog_state = convo_state.create_property("dialogState")
        dialogs = DialogSet(dialog_state)
        dialogs.add(
            OAuthPrompt(
                "prompt", OAuthPromptSettings(connection_name, "Login", None, 300000)
            )
        )

        await adapter.send("Hello")
        self.assertTrue(called)
Example #11
0
    def __init__(self, configuration: DefaultConfig):
        super().__init__(MainDialog.__name__)

        self._connection_name = configuration.CONNECTION_NAME

        self.add_dialog(
            OAuthPrompt(
                OAuthPrompt.__name__,
                OAuthPromptSettings(
                    connection_name=self._connection_name,
                    text=f"Sign In to AAD",
                    title="Sign In",
                ),
            ))

        self.add_dialog(
            WaterfallDialog(WaterfallDialog.__name__,
                            [self._sign_in_step, self._show_token_response]))

        self.initial_dialog_id = WaterfallDialog.__name__
Example #12
0
    def __init__(
        self,
        configuration,
    ):
        super().__init__(MainDialog.__name__, configuration.CONNECTION_NAME)

        self.add_dialog(
            OAuthPrompt(
                OAuthPrompt.__name__,
                OAuthPromptSettings(
                    connection_name=self.connection_name,
                    text="Please Sign In",
                    title="Sign In",
                    timeout=30000,
                )))
        self.add_dialog(ConfirmPrompt(ConfirmPrompt.__name__))
        self.add_dialog(
            WaterfallDialog("WFDialog", [
                self.prompt_step, self.login_step,
                self.display_token_phase_one, self.display_token_phase_two
            ]))

        self.initial_dialog_id = "WFDialog"