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

Source 3PL Central: add a check for HTTP URLs in config #18763

Merged

Conversation

arsenlosenko
Copy link
Contributor

What

Resolving:
#16521

How

  • added a simple check for the url_base parameter in config, so in case of HTTP base URL the ConfigurationError would be raised. And added a test to cover this case

Recommended reading order

  1. x.java
  2. y.python

🚨 User Impact 🚨

Are there any breaking changes? What is the end result perceived by the user? If yes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the connector is published, connector added to connector index as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here
Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub and connector version bumped by running the /publish command described here
Connector Generator
  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed

Tests

Unit

Put your unit tests output here.

Integration

Put your integration tests output here.

Acceptance

Put your acceptance tests output here.

@CLAassistant
Copy link

CLAassistant commented Nov 1, 2022

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added area/connectors Connector related issues area/documentation Improvements or additions to documentation labels Nov 1, 2022
@arsenlosenko
Copy link
Contributor Author

arsenlosenko commented Nov 1, 2022

/test connector=connectors/source-tplcentral

🕑 connectors/source-tplcentral https://github.com/airbytehq/airbyte/actions/runs/3368546234
❌ connectors/source-tplcentral https://github.com/airbytehq/airbyte/actions/runs/3368546234
🐛 https://gradle.com/s/oyw44wfre4exk

Build Failed

Test summary info:

	 =========================== short test summary info ============================
	 FAILED unit_tests/test_source.py::test_check_connection - assert (None,\n Exc...
	 FAILED unit_tests/test_source.py::test_streams - source_tplcentral.source.Con...
	 �[31m================== �[31m�[1m2 failed�[0m, �[32m20 passed�[0m, �[33m38 warnings�[0m�[31m in 1.64s�[0m�[31m ===================�[0m

@arsenlosenko arsenlosenko linked an issue Nov 1, 2022 that may be closed by this pull request
@arsenlosenko
Copy link
Contributor Author

arsenlosenko commented Nov 3, 2022

/test connector=connectors/source-tplcentral

🕑 connectors/source-tplcentral https://github.com/airbytehq/airbyte/actions/runs/3385747174
❌ connectors/source-tplcentral https://github.com/airbytehq/airbyte/actions/runs/3385747174
🐛 https://gradle.com/s/5k4s25g7scnd6

Build Failed

Test summary info:

	 =========================== short test summary info ============================
	 FAILED unit_tests/test_source.py::test_check_connection - assert (None,\n Exc...
	 �[31m================== �[31m�[1m1 failed�[0m, �[32m21 passed�[0m, �[33m50 warnings�[0m�[31m in 1.68s�[0m�[31m ===================�[0m

@arsenlosenko
Copy link
Contributor Author

arsenlosenko commented Nov 8, 2022

/test connector=connectors/source-tplcentral

🕑 connectors/source-tplcentral https://github.com/airbytehq/airbyte/actions/runs/3419976288
❌ connectors/source-tplcentral https://github.com/airbytehq/airbyte/actions/runs/3419976288
🐛 https://gradle.com/s/6n6x43kb5sxri

Build Failed

Test summary info:

=========================== short test summary info ============================
FAILED test_core.py::TestSpec::test_additional_properties_is_true[inputs0] - ...
ERROR test_core.py::TestSpec::test_config_match_spec[inputs0] - FileNotFoundE...
ERROR test_core.py::TestConnection::test_check[inputs0] - FileNotFoundError: ...
ERROR test_core.py::TestDiscovery::test_discover[inputs0] - FileNotFoundError...
ERROR test_core.py::TestDiscovery::test_defined_cursors_exist_in_schema[inputs0]
ERROR test_core.py::TestDiscovery::test_defined_refs_exist_in_schema[inputs0]
ERROR test_core.py::TestDiscovery::test_defined_keyword_exist_in_schema[inputs0-allOf]
ERROR test_core.py::TestDiscovery::test_defined_keyword_exist_in_schema[inputs0-not]
ERROR test_core.py::TestDiscovery::test_primary_keys_exist_in_schema[inputs0]
ERROR test_core.py::TestDiscovery::test_streams_has_sync_modes[inputs0] - Fil...
ERROR test_core.py::TestDiscovery::test_additional_properties_is_true[inputs0]
ERROR test_core.py::TestDiscovery::test_backward_compatibility[inputs0] - Fil...
ERROR test_core.py::TestBasicRead::test_read[inputs0] - FileNotFoundError: [E...
ERROR test_core.py::TestBasicRead::test_read[inputs1] - FileNotFoundError: [E...
ERROR test_core.py::TestBasicRead::test_read[inputs2] - FileNotFoundError: [E...
ERROR test_core.py::TestBasicRead::test_read[inputs3] - FileNotFoundError: [E...
ERROR test_core.py::TestBasicRead::test_read[inputs4] - FileNotFoundError: [E...
ERROR test_core.py::TestBasicRead::test_read[inputs5] - FileNotFoundError: [E...
ERROR test_core.py::TestBasicRead::test_airbyte_trace_message_on_failure[inputs0]
ERROR test_core.py::TestBasicRead::test_airbyte_trace_message_on_failure[inputs1]
ERROR test_core.py::TestBasicRead::test_airbyte_trace_message_on_failure[inputs2]
ERROR test_core.py::TestBasicRead::test_airbyte_trace_message_on_failure[inputs3]
ERROR test_core.py::TestBasicRead::test_airbyte_trace_message_on_failure[inputs4]
ERROR test_core.py::TestBasicRead::test_airbyte_trace_message_on_failure[inputs5]
ERROR test_full_refresh.py::TestFullRefresh::test_sequential_reads[inputs0]
ERROR test_full_refresh.py::TestFullRefresh::test_sequential_reads[inputs1]
ERROR test_incremental.py::TestIncremental::test_two_sequential_reads[inputs0]
ERROR test_incremental.py::TestIncremental::test_two_sequential_reads[inputs1]
ERROR test_incremental.py::TestIncremental::test_two_sequential_reads[inputs2]
ERROR test_incremental.py::TestIncremental::test_two_sequential_reads[inputs3]
ERROR test_incremental.py::TestIncremental::test_read_sequential_slices[inputs0]
ERROR test_incremental.py::TestIncremental::test_read_sequential_slices[inputs1]
ERROR test_incremental.py::TestIncremental::test_read_sequential_slices[inputs2]
ERROR test_incremental.py::TestIncremental::test_read_sequential_slices[inputs3]
ERROR test_incremental.py::TestIncremental::test_state_with_abnormally_large_values[inputs0]
ERROR test_incremental.py::TestIncremental::test_state_with_abnormally_large_values[inputs1]
ERROR test_incremental.py::TestIncremental::test_state_with_abnormally_large_values[inputs2]
ERROR test_incremental.py::TestIncremental::test_state_with_abnormally_large_values[inputs3]
============ 1 failed, 11 passed, 29 warnings, 37 errors in 15.87s =============

@arsenlosenko arsenlosenko changed the title Source TPI Central: add a check for HTTP URLs in config Source 3PL Central: add a check for HTTP URLs in config Nov 8, 2022
@arsenlosenko
Copy link
Contributor Author

local unit test results:

============================= test session starts ==============================
platform linux -- Python 3.9.11, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /home/arsenlosenko/.pyenv/versions/3.9.11/envs/source-tplcentral/bin/python3.9
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/arsenlosenko/projects/airbyteio/airbyte/airbyte-integrations/connectors/source-tplcentral/.hypothesis/examples')
rootdir: /home/arsenlosenko/projects/airbyteio/airbyte, configfile: pytest.ini
plugins: hypothesis-6.54.6, mock-3.6.1, timeout-1.4.2, cov-3.0.0, requests-mock-1.9.3, sugar-0.9.5
collecting ... collected 22 items

unit_tests/test_incremental_streams.py::test_cursor_field PASSED
unit_tests/test_incremental_streams.py::test_get_updated_state PASSED
unit_tests/test_incremental_streams.py::test_stream_slices PASSED
unit_tests/test_incremental_streams.py::test_supports_incremental PASSED
unit_tests/test_incremental_streams.py::test_source_defined_cursor PASSED
unit_tests/test_incremental_streams.py::test_stream_checkpoint_interval PASSED
unit_tests/test_source.py::test_check_connection PASSED
unit_tests/test_source.py::test_auth_raises_configuration_error {"type": "LOG", "log": {"level": "ERROR", "message": "'url_base' parameter should be a HTTPS URL"}}
PASSED
unit_tests/test_source.py::test_streams PASSED
unit_tests/test_streams.py::test_request_params PASSED
unit_tests/test_streams.py::test_next_page_token PASSED
unit_tests/test_streams.py::test_next_page_token_with_page_size PASSED
unit_tests/test_streams.py::test_parse_response PASSED
unit_tests/test_streams.py::test_parse_response_with_primary_key PASSED
unit_tests/test_streams.py::test_parse_response_with_cursor_field PASSED
unit_tests/test_streams.py::test_request_headers PASSED
unit_tests/test_streams.py::test_http_method PASSED
unit_tests/test_streams.py::test_should_retry[HTTPStatus.OK-False] PASSED
unit_tests/test_streams.py::test_should_retry[HTTPStatus.BAD_REQUEST-False] PASSED
unit_tests/test_streams.py::test_should_retry[HTTPStatus.TOO_MANY_REQUESTS-True] PASSED
unit_tests/test_streams.py::test_should_retry[HTTPStatus.INTERNAL_SERVER_ERROR-True] PASSED
unit_tests/test_streams.py::test_backoff_time PASSED

=============================== warnings summary ===============================
airbyte-integrations/connectors/source-tplcentral/unit_tests/test_incremental_streams.py: 6 warnings
airbyte-integrations/connectors/source-tplcentral/unit_tests/test_source.py: 6 warnings
airbyte-integrations/connectors/source-tplcentral/unit_tests/test_streams.py: 13 warnings
  /home/arsenlosenko/.pyenv/versions/3.9.11/envs/source-tplcentral/lib/python3.9/site-packages/airbyte_cdk/sources/streams/http/http.py:43: DeprecationWarning: Call to deprecated class NoAuth. (Set `authenticator=None` instead) -- Deprecated since version 0.1.20.
    self._authenticator: HttpAuthenticator = NoAuth()

airbyte-integrations/connectors/source-tplcentral/unit_tests/test_incremental_streams.py: 6 warnings
airbyte-integrations/connectors/source-tplcentral/unit_tests/test_source.py: 6 warnings
airbyte-integrations/connectors/source-tplcentral/unit_tests/test_streams.py: 13 warnings
  /home/arsenlosenko/.pyenv/versions/3.9.11/envs/source-tplcentral/lib/python3.9/site-packages/deprecated/classic.py:173: DeprecationWarning: Call to deprecated class HttpAuthenticator. (Use requests.auth.AuthBase instead) -- Deprecated since version 0.1.20.
    return old_new1(cls, *args, **kwargs)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================= 22 passed, 50 warnings in 0.39s ========================

@arsenlosenko arsenlosenko requested review from darynaishchenko and removed request for roman-yermilov-gl November 9, 2022 08:42
@arsenlosenko
Copy link
Contributor Author

as stated in this #16521 (comment), we cannot run integration tests for this connector as of now, so we can only rely on unit tests. Results of local test suite run is in the previous comment.

@@ -63,6 +75,11 @@ def refresh_access_token(self) -> Tuple[str, int]:

class SourceTplcentral(AbstractSource):
def _auth(self, config):
url_base = config.get("url_base")
if url_base.startswith("http://"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if I enter "url_base" like "HtTp://" ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arsenlosenko I suggest you'd better restrict this using regexp in a spec like here and add a SAT test instead of a unit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davydov-d yep, it should be a better solution, I'll do that then, thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grubberr can you check again please, I've made the changes that were suggested

@grubberr grubberr self-requested a review November 9, 2022 15:11
@arsenlosenko arsenlosenko merged commit 61931e6 into master Nov 9, 2022
@arsenlosenko arsenlosenko deleted the arsenlosenko/16521-source-tplcentral-prevent-http branch November 9, 2022 15:11
akashkulk pushed a commit that referenced this pull request Dec 2, 2022
* Source TPI Central: add a check for HTTP URLs in config

* Update changelog

* Fix tests

* Add missing attributes to fix the test that wasn't working

* Add HTTPS URL check to SAT tests

* Remove previously added changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues area/documentation Improvements or additions to documentation connectors/source/tplcentral
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add check to prevent users from using http url with Tplcentral
5 participants