square-authentication 6.0.4__py3-none-any.whl → 6.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,9 @@ try:
22
22
  # environment
23
23
  config_str_host_ip = ldict_configuration["ENVIRONMENT"]["HOST_IP"]
24
24
  config_int_host_port = int(ldict_configuration["ENVIRONMENT"]["HOST_PORT"])
25
+ config_list_allow_origins = eval(
26
+ ldict_configuration["ENVIRONMENT"]["ALLOW_ORIGINS"]
27
+ )
25
28
  config_str_log_file_name = ldict_configuration["ENVIRONMENT"]["LOG_FILE_NAME"]
26
29
  config_str_secret_key_for_access_token = ldict_configuration["ENVIRONMENT"][
27
30
  "SECRET_KEY_FOR_ACCESS_TOKEN"
@@ -4,6 +4,7 @@ MODULE_NAME = square_authentication
4
4
  [ENVIRONMENT]
5
5
  HOST_IP = 0.0.0.0
6
6
  HOST_PORT = 10011
7
+ ALLOW_ORIGINS = ["http://localhost:10011"]
7
8
 
8
9
  LOG_FILE_NAME = square_authentication
9
10
 
@@ -4,6 +4,7 @@ MODULE_NAME = square_authentication
4
4
  [ENVIRONMENT]
5
5
  HOST_IP = 0.0.0.0
6
6
  HOST_PORT = 10011
7
+ ALLOW_ORIGINS = ["http://localhost:10011"]
7
8
 
8
9
  LOG_FILE_NAME = square_authentication
9
10
 
@@ -13,6 +13,7 @@ from square_authentication.configuration import (
13
13
  config_str_module_name,
14
14
  config_str_ssl_key_file_path,
15
15
  config_str_ssl_crt_file_path,
16
+ config_list_allow_origins,
16
17
  )
17
18
  from square_authentication.routes import core, utility, profile
18
19
 
@@ -21,7 +22,7 @@ app = FastAPI()
21
22
  app.add_middleware(
22
23
  CORSMiddleware,
23
24
  allow_credentials=True,
24
- allow_origins=["*"],
25
+ allow_origins=config_list_allow_origins,
25
26
  allow_methods=["*"],
26
27
  allow_headers=["*"],
27
28
  )
@@ -5,6 +5,7 @@ messages = {
5
5
  "INCORRECT_USERNAME": "the username you entered does not exist.",
6
6
  "INCORRECT_PASSWORD": "the password you entered is incorrect. please try again.",
7
7
  "INCORRECT_USER_ID": "the user ID you provided does not exist or is invalid.",
8
+ "USERNAME_INVALID": "username must start and end with a lowercase letter and can include only lowercase letters, digits, underscores, or hyphens. no spaces, no dots, and no consecutive special characters.",
8
9
  "USERNAME_ALREADY_EXISTS": "the username you entered is already taken. please choose a different one.",
9
10
  "INCORRECT_ACCESS_TOKEN": "the access token provided is invalid or expired.",
10
11
  "INCORRECT_REFRESH_TOKEN": "the refresh token provided is invalid or expired.",
@@ -1,4 +1,5 @@
1
1
  import copy
2
+ import re
2
3
  from datetime import datetime, timedelta, timezone
3
4
  from typing import Annotated, List
4
5
 
@@ -67,6 +68,22 @@ async def register_username_v0(
67
68
  validation
68
69
  """
69
70
  # validation for username
71
+ # ^(?!.*[_-]{2}) # no consecutive _ or -
72
+ # [a-z] # must start with a lowercase letter
73
+ # (?:[a-z0-9_-]{1,18}) # 1–18 of lowercase, digits, _ or -
74
+ # [a-z]$ # must end with a lowercase letter
75
+ username_pattern = re.compile(r"^(?!.*[._-]{2})[a-z][a-z0-9_-]{1,18}[a-z]$")
76
+ if not username_pattern.match(username):
77
+ output_content = get_api_output_in_standard_format(
78
+ message=messages["USERNAME_INVALID"],
79
+ log=f"username '{username}' is invalid. it must start and end with a letter, "
80
+ f"contain only lowercase letters, numbers, underscores, or hyphens, "
81
+ f"and not have consecutive separators.",
82
+ )
83
+ raise HTTPException(
84
+ status_code=status.HTTP_400_BAD_REQUEST,
85
+ detail=output_content,
86
+ )
70
87
  local_list_response_user_creds = (
71
88
  global_object_square_database_helper.get_rows_v0(
72
89
  database_name=global_string_database_name,
@@ -1098,6 +1115,25 @@ async def update_username_v0(
1098
1115
  )
1099
1116
  user_id = local_dict_access_token_payload["user_id"]
1100
1117
 
1118
+ # validation for username
1119
+ # ^(?!.*[_-]{2}) # no consecutive _ or -
1120
+ # [a-z] # must start with a lowercase letter
1121
+ # (?:[a-z0-9_-]{1,18}) # 1–18 of lowercase, digits, _ or -
1122
+ # [a-z]$ # must end with a lowercase letter
1123
+ new_username = new_username.lower()
1124
+ username_pattern = re.compile(r"^(?!.*[._-]{2})[a-z][a-z0-9_-]{1,18}[a-z]$")
1125
+ if not username_pattern.match(new_username):
1126
+ output_content = get_api_output_in_standard_format(
1127
+ message=messages["USERNAME_INVALID"],
1128
+ log=f"username '{new_username}' is invalid. it must start and end with a letter, "
1129
+ f"contain only lowercase letters, numbers, underscores, or hyphens, "
1130
+ f"and not have consecutive separators.",
1131
+ )
1132
+ raise HTTPException(
1133
+ status_code=status.HTTP_400_BAD_REQUEST,
1134
+ detail=output_content,
1135
+ )
1136
+
1101
1137
  # validate user_id
1102
1138
  local_list_user_response = global_object_square_database_helper.get_rows_v0(
1103
1139
  database_name=global_string_database_name,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: square_authentication
3
- Version: 6.0.4
3
+ Version: 6.1.0
4
4
  Summary: authentication layer for my personal server.
5
5
  Home-page: https://github.com/thepmsquare/square_authentication
6
6
  Author: thePmSquare
@@ -53,6 +53,16 @@ pip install square_authentication
53
53
 
54
54
  ## changelog
55
55
 
56
+ ### v6.1.0
57
+
58
+ - add validation to username in register_username_v0 and update_username_v0.
59
+ - add test cases for register_username_v0.
60
+
61
+ ### v6.0.5
62
+
63
+ - env
64
+ - add ALLOW_ORIGINS
65
+
56
66
  ### v6.0.4
57
67
 
58
68
  - mock ini file for pytest.
@@ -1,19 +1,19 @@
1
1
  square_authentication/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- square_authentication/configuration.py,sha256=o-fx1zLipECyEQQm7jtMR2hYBW3gZ6uyFojSzuJ7Pqs,4475
3
- square_authentication/main.py,sha256=zADc2vmV8yDylmbihj4FzLDEs5b-9nItFoB5c4AoKGk,1704
4
- square_authentication/messages.py,sha256=vhcl4bw8Ar1npiErjGh3kkNPmW1rmDRtf6rKn5JF8W8,1364
5
- square_authentication/data/config.ini,sha256=mJUGsEMqpAOVrHW3KmiZzH92340DkX69wDG4jBv1YWw,1111
6
- square_authentication/data/config.testing.ini,sha256=wW727RRUgQl4euKJ17uLqlVJTrQ6ISER_9GA5GgW83o,1158
2
+ square_authentication/configuration.py,sha256=zdlBY7xyMoEl8fc2whpXqsILvvrNnFGC1Yry_pB6FaI,4579
3
+ square_authentication/main.py,sha256=nhkv8U4E9b7VIH7Aaj8iMWIwA4VIL-vzRXjZaYEFWPw,1755
4
+ square_authentication/messages.py,sha256=WVZtWBctx-YK1xGo97DFAMkSgCZpDEd9gABBSqlvd58,1575
5
+ square_authentication/data/config.ini,sha256=Mayh9AhTBZd8i08Y--ClZuDEjJjfvnfKQmtqablzXOA,1154
6
+ square_authentication/data/config.testing.ini,sha256=KB4PMPZ6a9yJGPXYJWwKlYcNET1Au3TQdJHQyngbZUA,1201
7
7
  square_authentication/pydantic_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  square_authentication/pydantic_models/core.py,sha256=qeNETcJv7mnRKGhATOW2bg0NlHuyzvot1dZ1b1qqhwU,610
9
9
  square_authentication/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- square_authentication/routes/core.py,sha256=Ui2kJI3DHK1tsb4_cCle8iurZlU__O_nptk2-YLZ2vg,56778
10
+ square_authentication/routes/core.py,sha256=Gu7Z6gcQqKqXOwT-uHYWBJHWvJ_CVVT7BQC-afhwGyU,58717
11
11
  square_authentication/routes/profile.py,sha256=3b-PtMaD9cxvf112MOn9rPu5F2KG4sRxAbuPvll8dUU,6216
12
12
  square_authentication/routes/utility.py,sha256=KDr8KdkT0jAGPjfP-b5XXYG7p49WU7J1FiK6oSIckQI,1779
13
13
  square_authentication/utils/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
14
14
  square_authentication/utils/encryption.py,sha256=WakaiEAgWpTJltxBzqOtv81_DCDKfzJqt60fWSPoNvo,2027
15
15
  square_authentication/utils/token.py,sha256=t-RPBY4cYyT1ro3lkLBTOy2BeRGBfluBVBivL5DLmDg,680
16
- square_authentication-6.0.4.dist-info/METADATA,sha256=xvcPTkLQ-Z-DREOI_0tmIlwsu-vXuT8skKTfQ8vJKBA,5158
17
- square_authentication-6.0.4.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
18
- square_authentication-6.0.4.dist-info/top_level.txt,sha256=wDssVJIl9KIEJPj5rR3rv4uRI7yCndMBrvHd_6BGXQA,22
19
- square_authentication-6.0.4.dist-info/RECORD,,
16
+ square_authentication-6.1.0.dist-info/METADATA,sha256=Q6YHK0bIbx0Zs1AkqRjwJZG3aXNBMQdsBdtp7n-GfhE,5334
17
+ square_authentication-6.1.0.dist-info/WHEEL,sha256=QZxptf4Y1BKFRCEDxD4h2V0mBFQOVFLFEpvxHmIs52A,91
18
+ square_authentication-6.1.0.dist-info/top_level.txt,sha256=wDssVJIl9KIEJPj5rR3rv4uRI7yCndMBrvHd_6BGXQA,22
19
+ square_authentication-6.1.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.3.1)
2
+ Generator: setuptools (80.6.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5