diff --git a/social_core/backends/base.py b/social_core/backends/base.py index 71a1c8bce..be8f5ec1c 100644 --- a/social_core/backends/base.py +++ b/social_core/backends/base.py @@ -190,7 +190,7 @@ def get_user_names(self, fullname="", first_name="", last_name=""): except ValueError: first_name = first_name or fullname or "" last_name = last_name or "" - fullname = fullname or " ".join((first_name, last_name)) + fullname = fullname or f"{first_name} {last_name}" return fullname.strip(), first_name.strip(), last_name.strip() def get_user(self, user_id): diff --git a/social_core/backends/lastfm.py b/social_core/backends/lastfm.py index 735d3d422..941c634fb 100644 --- a/social_core/backends/lastfm.py +++ b/social_core/backends/lastfm.py @@ -28,9 +28,7 @@ def auth_complete(self, *args, **kwargs): token = self.data["token"] signature = hashlib.md5( - "".join( - ("api_key", key, "methodauth.getSession", "token", token, secret) - ).encode() + f"api_key{key}methodauth.getSessiontoken{token}{secret}".encode() ).hexdigest() response = self.get_json( diff --git a/social_core/backends/yahoo.py b/social_core/backends/yahoo.py index a5ef64b7c..20c18da98 100644 --- a/social_core/backends/yahoo.py +++ b/social_core/backends/yahoo.py @@ -74,7 +74,7 @@ class YahooOAuth2(BaseOAuth2): def get_user_names(self, first_name, last_name): if first_name or last_name: - return " ".join((first_name, last_name)), first_name, last_name + return f"{first_name} {last_name}", first_name, last_name return None, None, None def get_user_details(self, response): diff --git a/social_core/tests/backends/test_livejournal.py b/social_core/tests/backends/test_livejournal.py index b25836613..aaba8790a 100644 --- a/social_core/tests/backends/test_livejournal.py +++ b/social_core/tests/backends/test_livejournal.py @@ -14,19 +14,15 @@ class LiveJournalOpenIdTest(OpenIdTest): backend_path = "social_core.backends.livejournal.LiveJournalOpenId" expected_username = "foobar" - discovery_body = "".join( - [ - '', - "", - '', - "http://specs.openid.net/auth/2.0/signon", - "http://www.livejournal.com/openid/server.bml", - "http://foobar.livejournal.com/", - "", - "", - "", - ] - ) + discovery_body = """ + + + http://specs.openid.net/auth/2.0/signon + http://www.livejournal.com/openid/server.bml + http://foobar.livejournal.com/ + + +""" server_response = urlencode( { "janrain_nonce": JANRAIN_NONCE, @@ -44,20 +40,14 @@ class LiveJournalOpenIdTest(OpenIdTest): "openid.sig": "Z8MOozVPTOBhHG5ZS1NeGofxs1Q=", } ) - server_bml_body = "\n".join( - [ - "assoc_handle:1364935340:ZhruPQ7DJ9eGgUkeUA9A:27f8c32464", - "assoc_type:HMAC-SHA1", - "dh_server_public:WzsRyLomvAV3vwvGUrfzXDgfqnTF+m1l3JWb55fyHO7visPT4tmQ" - "iTjqFFnSVAtAOvQzoViMiZQisxNwnqSK4lYexoez1z6pP5ry3pqxJAEYj60vFGvRztict" - "Eo0brjhmO1SNfjK1ppjOymdykqLpZeaL5fsuLtMCwTnR/JQZVA=", - "enc_mac_key:LiOEVlLJSVUqfNvb5zPd76nEfvc=", - "expires_in:1207060", - "ns:http://specs.openid.net/auth/2.0", - "session_type:DH-SHA1", - "", - ] - ) + server_bml_body = """assoc_handle:1364935340:ZhruPQ7DJ9eGgUkeUA9A:27f8c32464 +assoc_type:HMAC-SHA1 +dh_server_public:WzsRyLomvAV3vwvGUrfzXDgfqnTF+m1l3JWb55fyHO7visPT4tmQiTjqFFnSVAtAOvQzoViMiZQisxNwnqSK4lYexoez1z6pP5ry3pqxJAEYj60vFGvRztictEo0brjhmO1SNfjK1ppjOymdykqLpZeaL5fsuLtMCwTnR/JQZVA= +enc_mac_key:LiOEVlLJSVUqfNvb5zPd76nEfvc= +expires_in:1207060 +ns:http://specs.openid.net/auth/2.0 +session_type:DH-SHA1 +""" def openid_url(self): return super().openid_url() + "/data/yadis" diff --git a/social_core/tests/backends/test_ngpvan.py b/social_core/tests/backends/test_ngpvan.py index 9173ff6e6..66ca3b513 100644 --- a/social_core/tests/backends/test_ngpvan.py +++ b/social_core/tests/backends/test_ngpvan.py @@ -17,30 +17,23 @@ class NGPVANActionIDOpenIDTest(OpenIdTest): backend_path = "social_core.backends.ngpvan.ActionIDOpenID" expected_username = "testuser@user.local" - discovery_body = " ".join( - [ - '', - "', - "", - '', - "http://specs.openid.net/auth/2.0/signon", - "http://openid.net/extensions/sreg/1.1", - "http://axschema.org/contact/email", - "https://accounts.ngpvan.com/OpenId/Provider", - "", - '', - "http://openid.net/signon/1.0", - "http://openid.net/extensions/sreg/1.1", - "http://axschema.org/contact/email", - "https://accounts.ngpvan.com/OpenId/Provider", - "", - "", - "", - ] - ) + discovery_body = """ + + + + http://specs.openid.net/auth/2.0/signon + http://openid.net/extensions/sreg/1.1 + http://axschema.org/contact/email + https://accounts.ngpvan.com/OpenId/Provider + + + http://openid.net/signon/1.0 + http://openid.net/extensions/sreg/1.1 + http://axschema.org/contact/email + https://accounts.ngpvan.com/OpenId/Provider + + +""" server_response = urlencode( { "openid.claimed_id": "https://accounts.ngpvan.com/user/abcd123", diff --git a/social_core/tests/backends/test_open_id_connect.py b/social_core/tests/backends/test_open_id_connect.py index f57db5967..19c5d963e 100644 --- a/social_core/tests/backends/test_open_id_connect.py +++ b/social_core/tests/backends/test_open_id_connect.py @@ -166,7 +166,7 @@ def prepare_access_token_body( header, msg, sig = body["id_token"].split(".") id_token["sub"] = "1235" msg = base64.encodebytes(json.dumps(id_token).encode()).decode() - body["id_token"] = ".".join([header, msg, sig]) + body["id_token"] = f"{header}.{msg}.{sig}" return json.dumps(body) diff --git a/social_core/tests/backends/test_steam.py b/social_core/tests/backends/test_steam.py index 6798e453c..9f11afad5 100644 --- a/social_core/tests/backends/test_steam.py +++ b/social_core/tests/backends/test_steam.py @@ -14,32 +14,24 @@ class SteamOpenIdTest(OpenIdTest): backend_path = "social_core.backends.steam.SteamOpenId" expected_username = "foobar" - discovery_body = "".join( - [ - '', - '', - "", - '', - "http://specs.openid.net/auth/2.0/server", - "https://steamcommunity.com/openid/login", - "", - "", - "", - ] - ) - user_discovery_body = "".join( - [ - '', - '', - "", - '', - "http://specs.openid.net/auth/2.0/signon ", - "https://steamcommunity.com/openid/login", - "", - "", - "", - ] - ) + discovery_body = """ + + + + http://specs.openid.net/auth/2.0/server + https://steamcommunity.com/openid/login + + +""" + user_discovery_body = """ + + + + http://specs.openid.net/auth/2.0/signon + https://steamcommunity.com/openid/login + + +""" server_response = urlencode( { "janrain_nonce": JANRAIN_NONCE,