Skip to content
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
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "fe574b1", "specHash": "a8825be", "version": "1.14.0" }
{ "engineHash": "20cb559", "specHash": "a8825be", "version": "1.14.0" }
4 changes: 3 additions & 1 deletion box_sdk_gen/box/ccg_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def downscope_token(
:param network_session: An object to keep network session state, defaults to None
:type network_session: Optional[NetworkSession], optional
"""
token: Optional[AccessToken] = self.token_storage.get()
token: Optional[AccessToken] = self.retrieve_token(
network_session=network_session
)
if token == None:
raise BoxSDKError(
message='No access token is available. Make an API call to retrieve a token before calling this method.'
Expand Down
4 changes: 3 additions & 1 deletion box_sdk_gen/box/developer_token_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def downscope_token(
:param network_session: An object to keep network session state, defaults to None
:type network_session: Optional[NetworkSession], optional
"""
token: Optional[AccessToken] = self.token_storage.get()
token: Optional[AccessToken] = self.retrieve_token(
network_session=network_session
)
if token == None or token.access_token == None:
raise BoxSDKError(message='No access token is available.')
auth_manager: AuthorizationManager = AuthorizationManager(
Expand Down
4 changes: 3 additions & 1 deletion box_sdk_gen/box/jwt_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ def downscope_token(
:param network_session: An object to keep network session state, defaults to None
:type network_session: Optional[NetworkSession], optional
"""
token: Optional[AccessToken] = self.token_storage.get()
token: Optional[AccessToken] = self.retrieve_token(
network_session=network_session
)
if token == None:
raise BoxSDKError(
message='No access token is available. Make an API call to retrieve a token before calling this method.'
Expand Down
4 changes: 3 additions & 1 deletion box_sdk_gen/box/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ def downscope_token(
:param network_session: An object to keep network session state, defaults to None
:type network_session: Optional[NetworkSession], optional
"""
token: Optional[AccessToken] = self.token_storage.get()
token: Optional[AccessToken] = self.retrieve_token(
network_session=network_session
)
if token == None or token.access_token == None:
raise BoxSDKError(message='No access token is available.')
auth_manager: AuthorizationManager = AuthorizationManager(
Expand Down
62 changes: 62 additions & 0 deletions test/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ def test_jwt_auth_downscope():
parent_client.files.delete_file_by_id(file.id)


def test_jwt_downscope_token_succeeds_if_no_token_available():
jwt_config: JWTConfig = JWTConfig.from_config_json_string(
decode_base_64(get_env_var('JWT_CONFIG_BASE_64'))
)
auth: BoxJWTAuth = BoxJWTAuth(config=jwt_config)
downscoped_token: AccessToken = auth.downscope_token(['root_readonly'])
assert not downscoped_token.access_token == None
downscoped_client: BoxClient = BoxClient(
auth=BoxDeveloperTokenAuth(token=downscoped_token.access_token)
)
with pytest.raises(Exception):
downscoped_client.uploads.upload_file(
UploadFileAttributes(
name=get_uuid(), parent=UploadFileAttributesParentField(id='0')
),
generate_byte_stream(1024 * 1024),
)


def test_jwt_auth_revoke():
jwt_config: JWTConfig = JWTConfig.from_config_json_string(
decode_base_64(get_env_var('JWT_CONFIG_BASE_64'))
Expand Down Expand Up @@ -128,6 +147,16 @@ def test_oauth_auth_authorizeUrl():
)


def test_oauth_downscope_token_succeeds_if_no_token_available():
config: OAuthConfig = OAuthConfig(
client_id=get_env_var('CLIENT_ID'), client_secret=get_env_var('CLIENT_SECRET')
)
auth: BoxOAuth = BoxOAuth(config=config)
resource_path: str = ''.join(['https://api.box.com/2.0/files/12345'])
with pytest.raises(Exception):
auth.downscope_token(['item_rename', 'item_preview'], resource=resource_path)


def test_ccg_auth():
user_id: str = get_env_var('USER_ID')
enterprise_id: str = get_env_var('ENTERPRISE_ID')
Expand Down Expand Up @@ -175,6 +204,27 @@ def test_ccg_auth_downscope():
parent_client.folders.delete_folder_by_id(folder.id)


def test_ccg_downscope_token_succeeds_if_no_token_available():
ccg_config: CCGConfig = CCGConfig(
client_id=get_env_var('CLIENT_ID'),
client_secret=get_env_var('CLIENT_SECRET'),
user_id=get_env_var('USER_ID'),
)
auth: BoxCCGAuth = BoxCCGAuth(config=ccg_config)
downscoped_token: AccessToken = auth.downscope_token(['root_readonly'])
assert not downscoped_token.access_token == None
downscoped_client: BoxClient = BoxClient(
auth=BoxDeveloperTokenAuth(token=downscoped_token.access_token)
)
with pytest.raises(Exception):
downscoped_client.uploads.upload_file(
UploadFileAttributes(
name=get_uuid(), parent=UploadFileAttributesParentField(id='0')
),
generate_byte_stream(1024 * 1024),
)


def test_ccg_auth_revoke():
ccg_config: CCGConfig = CCGConfig(
client_id=get_env_var('CLIENT_ID'),
Expand All @@ -192,6 +242,18 @@ def test_ccg_auth_revoke():
)


def test_developer_downscope_token_succeeds_if_no_token_available():
developer_token_config: DeveloperTokenConfig = DeveloperTokenConfig(
client_id=get_env_var('CLIENT_ID'), client_secret=get_env_var('CLIENT_SECRET')
)
auth: BoxDeveloperTokenAuth = BoxDeveloperTokenAuth(
token='', config=developer_token_config
)
resource_path: str = ''.join(['https://api.box.com/2.0/folders/12345'])
with pytest.raises(Exception):
auth.downscope_token(['item_rename', 'item_preview'], resource=resource_path)


def get_access_token() -> AccessToken:
user_id: str = get_env_var('USER_ID')
enterprise_id: str = get_env_var('ENTERPRISE_ID')
Expand Down
4 changes: 3 additions & 1 deletion test/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def testEventSourceFileOrFolder():
assert len(events.entries) > 0
first_event: Event = events.entries[0]
source: File = first_event.source
assert to_string(source.type) == 'file' or to_string(source.type) == 'folder'
assert (
to_string(source.type) == 'file' or to_string(source.type) == 'folder'
) or to_string(source.type) == 'collaboration'
assert not source.id == ''


Expand Down
Loading