Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all Twilio references #981

Merged
merged 2 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ is completely normal for a development setup. If you see any of the following,
they can be safely ignored:

```
WARNING Twilio is not set up. You must set TWILIO_ACCOUNT_SID and TWILIO_TOKEN to use the Twilio ICE servers.
WARNING GEO_IP_LICENSE_KEY not set! Unable to download GeoIP database!
WARNING Unable to connect to RabbitMQ. Is it running?
ConnectionError: [Errno 111] Connect call failed ('127.0.0.1', 5672)
Expand Down
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pyyaml = "*"
sortedcontainers = "*"
sqlalchemy = ">=2.0.0"
trueskill = "*"
twilio = ">=7.0.0"
uvloop = {version = "*", markers = "sys_platform != 'win32'"}

[dev-packages]
Expand Down
208 changes: 92 additions & 116 deletions Pipfile.lock

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from server.control import ControlServer
from server.game_service import GameService
from server.health import HealthServer
from server.ice_servers.nts import TwilioNTS
from server.player_service import PlayerService
from server.profiler import Profiler
from server.protocol import QDataStreamProtocol, SimpleJsonProtocol
Expand Down Expand Up @@ -80,18 +79,9 @@ def done_handler(sig: int, frame):

# Set up services

twilio_nts = None
if config.TWILIO_ACCOUNT_SID:
twilio_nts = TwilioNTS()
else:
logger.warning(
"Twilio is not set up. You must set TWILIO_ACCOUNT_SID and TWILIO_TOKEN to use the Twilio ICE servers."
)

instance = server.ServerInstance(
"LobbyServer",
database,
twilio_nts,
loop
)
player_service: PlayerService = instance.services["player_service"]
Expand Down
4 changes: 0 additions & 4 deletions server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
from .game_service import GameService
from .gameconnection import GameConnection
from .geoip_service import GeoIpService
from .ice_servers.nts import TwilioNTS
from .ladder_service import LadderService
from .ladder_service.violation_service import ViolationService
from .lobbyconnection import LobbyConnection
Expand Down Expand Up @@ -153,15 +152,13 @@
self,
name: str,
database: FAFDatabase,
twilio_nts: Optional[TwilioNTS],
loop: asyncio.BaseEventLoop,
# For testing
_override_services: Optional[dict[str, Service]] = None
):
self.name = name
self._logger = logging.getLogger(self.name)
self.database = database
self.twilio_nts = twilio_nts
self.loop = loop

self.started = False
Expand All @@ -178,7 +175,6 @@
database=database,
geoip=self.services["geo_ip_service"],
game_service=self.services["game_service"],
nts_client=twilio_nts,
players=self.services["player_service"],
ladder_service=self.services["ladder_service"],
party_service=self.services["party_service"],
Expand Down Expand Up @@ -308,7 +304,7 @@
timeout=config.SHUTDOWN_GRACE_PERIOD
)
except asyncio.CancelledError:
self._logger.debug(

Check warning on line 307 in server/__init__.py

View check run for this annotation

Codecov / codecov/patch

server/__init__.py#L307

Added line #L307 was not covered by tests
"Stopped waiting for games to end due to forced shutdown"
)
except asyncio.TimeoutError:
Expand Down
3 changes: 0 additions & 3 deletions server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ def __init__(self):
self.MINORITY_BONUS = 1
self.MINORITY_BONUS_RATING_RANGE = 1250

self.TWILIO_ACCOUNT_SID = ""
self.TWILIO_TOKEN = ""
self.TWILIO_TTL = 86400
self.COTURN_HOSTS = []
self.COTURN_KEYS = []

Expand Down
4 changes: 1 addition & 3 deletions server/ice_servers/coturn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import time
from hashlib import sha1

from server.config import config


class CoturnHMAC:
def __init__(self, coturn_hosts=[], coturn_keys=[]):
Expand All @@ -21,7 +19,7 @@ def __init__(self, coturn_hosts=[], coturn_keys=[]):

def server_tokens(self, username="faf-user", ttl=None) -> list[dict[str]]:
if ttl is None:
ttl = config.TWILIO_TTL # pragma: no cover
ttl = 86400 # pragma: no cover

servers = []

Expand Down
42 changes: 0 additions & 42 deletions server/ice_servers/nts.py

This file was deleted.

8 changes: 1 addition & 7 deletions server/lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
)
from .geoip_service import GeoIpService
from .ice_servers.coturn import CoturnHMAC
from .ice_servers.nts import TwilioNTS
from .ladder_service import LadderService
from .oauth_service import OAuthService
from .party_service import PartyService
Expand All @@ -71,7 +70,6 @@
database: FAFDatabase,
game_service: GameService,
players: PlayerService,
nts_client: Optional[TwilioNTS],
geoip: GeoIpService,
ladder_service: LadderService,
party_service: PartyService,
Expand All @@ -82,7 +80,6 @@
self.geoip_service = geoip
self.game_service = game_service
self.player_service = players
self.nts_client = nts_client
self.coturn_generator = CoturnHMAC(config.COTURN_HOSTS, config.COTURN_KEYS)
self.ladder_service = ladder_service
self.party_service = party_service
Expand Down Expand Up @@ -201,7 +198,7 @@
"text": e.message
})
if not e.recoverable:
await self.abort(e.message)

Check warning on line 201 in server/lobbyconnection.py

View check run for this annotation

Codecov / codecov/patch

server/lobbyconnection.py#L201

Added line #L201 was not covered by tests
except (KeyError, ValueError) as e:
self._logger.exception(e)
await self.abort(f"Garbage command: {message}")
Expand Down Expand Up @@ -1146,15 +1143,12 @@
if not self.player:
return

ttl = config.TWILIO_TTL
ttl = 86400
ice_servers = self.coturn_generator.server_tokens(
username=self.player.id,
ttl=ttl
)

if self.nts_client:
ice_servers += await self.nts_client.server_tokens(ttl=ttl)

await self.send({
"command": "ice_servers",
"ice_servers": ice_servers,
Expand Down
10 changes: 0 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,3 @@ def coturn_credentials() -> Iterable[str]:
"I5BcpufNrBb4JDj80KY/7VATNis=",
"4wYEgoPz2MHf35Fva8NWulI3vVU="
]


@pytest.fixture
def twilio_sid():
return "a"


@pytest.fixture
def twilio_token():
return "token_a"
3 changes: 0 additions & 3 deletions tests/data/test_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ NEWBIE_BASE_MEAN: 500
NEWBIE_MIN_GAMES: 10
TOP_PLAYER_MIN_RATING: 1600

TWILIO_ACCOUNT_SID: ""
TWILIO_TOKEN: ""
TWILIO_TTL: 86400
COTURN_HOSTS: []
COTURN_KEYS: []

Expand Down
1 change: 0 additions & 1 deletion tests/integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ async def make_lobby_server(config):
instance = ServerInstance(
"UnitTestServer",
database,
twilio_nts=None,
loop=event_loop,
_override_services={
"broadcast_service": broadcast_service,
Expand Down
1 change: 0 additions & 1 deletion tests/integration_tests/test_server_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ async def test_multiple_contexts(
instance = ServerInstance(
"TestMultiContext",
database,
twilio_nts=None,
loop=event_loop,
_override_services={
"broadcast_service": broadcast_service,
Expand Down
1 change: 0 additions & 1 deletion tests/integration_tests/test_servercontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def make_connection() -> LobbyConnection:
database=mock.Mock(),
game_service=mock.Mock(),
players=mock.Mock(),
nts_client=mock.Mock(),
geoip=mock.Mock(),
ladder_service=mock.Mock(),
party_service=mock.Mock(),
Expand Down
35 changes: 0 additions & 35 deletions tests/unit_tests/test_ice.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
from unittest import mock

import pytest
from twilio.rest import Client as TwilioRestClient

from server.ice_servers.coturn import CoturnHMAC
from server.ice_servers.nts import TwilioNTS


@pytest.fixture
def coturn_hmac(coturn_hosts, coturn_keys):
return CoturnHMAC(coturn_hosts=coturn_hosts, coturn_keys=coturn_keys)


@pytest.fixture
def twilio(twilio_sid, twilio_token):
with mock.patch("twilio.rest.Client", mock.Mock(spec=TwilioRestClient)):
mocked = TwilioNTS(sid=twilio_sid, token=twilio_token)
mocked.client.tokens.create = mock.Mock(
return_value=FakeTwilioServers()
)
return mocked


class FakeTwilioServers:
def __init__(self):
self.ice_servers = \
{
"urls": ["a", "b", "c"],
"username": "d",
"credential": "e",
"credentialType": "f"
}


@mock.patch("time.time", mock.Mock(return_value=1000))
def test_coturn_tokens(coturn_hmac, coturn_hosts, coturn_credentials):
servers = coturn_hmac.server_tokens(username="faf-test", ttl=123456)
Expand All @@ -56,15 +33,3 @@ def test_coturn_tokens(coturn_hmac, coturn_hosts, coturn_credentials):

assert server["credential"] == credential
assert server["username"] == "124456:faf-test"


async def test_twilio_nts(twilio):
servers = await twilio.server_tokens(ttl=123456)
twilio.client.tokens.create.assert_called_once()
assert servers == \
{
"urls": ["a", "b", "c"],
"username": "d",
"credential": "e",
"credentialType": "f"
}
16 changes: 2 additions & 14 deletions tests/unit_tests/test_lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from server.gameconnection import GameConnection
from server.games import CustomGame, Game, GameState, InitMode, VisibilityState
from server.geoip_service import GeoIpService
from server.ice_servers.nts import TwilioNTS
from server.ladder_service import LadderService
from server.lobbyconnection import LobbyConnection
from server.matchmaker import Search
Expand Down Expand Up @@ -58,11 +57,6 @@ def mock_player(player_factory):
return player_factory("Dummy", player_id=42, lobby_connection_spec=None)


@pytest.fixture
def mock_nts_client():
return mock.create_autospec(TwilioNTS)


@pytest.fixture
def mock_players():
return mock.create_autospec(PlayerService)
Expand Down Expand Up @@ -92,15 +86,13 @@ def lobbyconnection(
mock_players,
mock_player,
mock_geoip,
mock_nts_client,
rating_service
):
lc = LobbyConnection(
database=database,
geoip=mock_geoip,
game_service=mock_games,
players=mock_players,
nts_client=mock_nts_client,
ladder_service=mock.create_autospec(LadderService),
party_service=mock.create_autospec(PartyService),
oauth_service=mock.create_autospec(OAuthService),
Expand Down Expand Up @@ -695,21 +687,18 @@ async def test_command_social_remove_friend(lobbyconnection, database):

async def test_command_ice_servers(
lobbyconnection: LobbyConnection,
mock_nts_client
):
lobbyconnection.send = mock.AsyncMock()
lobbyconnection.coturn_generator.server_tokens = mock.Mock(
return_value=["coturn_tokens"]
)
mock_nts_client.server_tokens.return_value = ["twilio_tokens"]

await lobbyconnection.on_message_received({"command": "ice_servers"})

mock_nts_client.server_tokens.assert_called_once()
lobbyconnection.send.assert_called_once_with({
"command": "ice_servers",
"ice_servers": ["coturn_tokens", "twilio_tokens"],
"ttl": config.TWILIO_TTL
"ice_servers": ["coturn_tokens"],
"ttl": 86400,
})


Expand Down Expand Up @@ -1076,7 +1065,6 @@ async def test_check_policy_conformity_fatal(lobbyconnection, policy_server):

async def test_abort_connection_if_banned(
lobbyconnection: LobbyConnection,
mock_nts_client
):
# test user that has never been banned
lobbyconnection.player.id = 1
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_server_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def test_auto_create_services():
instance = ServerInstance("TestCreateServices", None, None, None, None)
instance = ServerInstance("TestCreateServices", None, None, None)

assert instance.services != {}
assert isinstance(instance.services["player_service"], PlayerService)
Expand Down
Loading