Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Fix SignalR client code not reading responses correctly (#2626)
Browse files Browse the repository at this point in the history
The `Response` object must have the JSON loaded via `json()` (`backend.request` was updated but this callsite was missed).

Also, import the `Onefuzz` type so that this is type-checked to avoid the same problem in future.
  • Loading branch information
Porges authored Nov 15, 2022
1 parent e546f78 commit 07befc5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/cli/onefuzz/status/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@

from six.moves import input # workaround for static analysis

from ..api import Onefuzz
from .signalr import Stream

SIGNALR_CONNECT_TIMEOUT_SECONDS = 0.1


def log_entry(onefuzz: Any, entries: List[Any]) -> None:
def log_entry(onefuzz: Onefuzz, entries: List[Any]) -> None:
for entry in entries:
onefuzz.logger.info("%s", entry)


def raw(onefuzz: Any, logger: logging.Logger) -> None:
def raw(onefuzz: Onefuzz, logger: logging.Logger) -> None:
client = Stream(onefuzz, logger)
client.setup(lambda x: log_entry(onefuzz, x))

Expand Down
12 changes: 8 additions & 4 deletions src/cli/onefuzz/status/signalr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@
# Licensed under the MIT License.

import logging
from typing import Any, Callable, Optional, cast
from typing import Callable, Optional, cast

from signalrcore.hub_connection_builder import HubConnectionBuilder

from ..api import Onefuzz


class Stream:
connected = None
hub: Optional[HubConnectionBuilder] = None

def __init__(self, onefuzz: Any, logger: logging.Logger) -> None:
def __init__(self, onefuzz: Onefuzz, logger: logging.Logger) -> None:
self.onefuzz = onefuzz
self.logger = logger

def get_token(self) -> str:
negotiate = self.onefuzz._backend.request("POST", "negotiate")
response = self.onefuzz._backend.request("POST", "negotiate")
negotiate = response.json()
return cast(str, negotiate["accessToken"])

def setup(self, handler: Callable) -> None:
config = self.onefuzz._backend.request("POST", "negotiate")
response = self.onefuzz._backend.request("POST", "negotiate")
config = response.json()
url = config["url"].replace("https://", "wss://")
self.hub = (
HubConnectionBuilder()
Expand Down

0 comments on commit 07befc5

Please sign in to comment.