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

Strip Okta ISS URL of trailing slashes #763

Merged
merged 5 commits into from
Aug 22, 2024

Conversation

michelletran-codecov
Copy link
Contributor

Purpose/Motivation

This removes trailing slashes from their usage in the code, and also from saving to the database. This should fix issues where we validate the payload from Okta with the ISS URL (they send it without trailing slashes).

Links to relevant tickets

https://github.com/codecov/internal-issues/issues/709

What does this PR do?

  1. Strip the URL of trailing slashes at the point of using the URL
  2. Strip the URL of trailing slashes before saving to the DB

We probably don't need both, but having both will just be safer.

Notes to Reviewer

Anything to note to the team? Any tips on how to review, or where to start?

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@michelletran-codecov michelletran-codecov changed the title 709 strip trailing slashes Strip Okta ISS URL of trailing slashes Aug 21, 2024
@michelletran-codecov michelletran-codecov force-pushed the 709_strip_trailing_slashes branch from 4ccbe94 to 62df390 Compare August 21, 2024 17:56
@michelletran-codecov michelletran-codecov marked this pull request as ready for review August 21, 2024 18:01
@michelletran-codecov michelletran-codecov requested review from a team August 21, 2024 18:02
@codecov-notifications
Copy link

codecov-notifications bot commented Aug 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link

codecov bot commented Aug 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.16%. Comparing base (fc63977) to head (b2b79ec).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##               main       #763   +/-   ##
===========================================
  Coverage   96.16000   96.16000           
===========================================
  Files           814        814           
  Lines         18423      18424    +1     
===========================================
+ Hits          17716      17717    +1     
  Misses          707        707           
Flag Coverage Δ
unit 91.91% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 91.91% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This strips the URLs of trailing slashes before we use them.
This is because the ISS URL currently assumes that the URL doesn't end in
a slash.
This saves the URL without the trailing slashes.
@michelletran-codecov michelletran-codecov force-pushed the 709_strip_trailing_slashes branch from 62df390 to 832647e Compare August 21, 2024 18:19
@codecov-qa
Copy link

codecov-qa bot commented Aug 21, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
2253 1 2252 6
View the top 1 failed tests by shortest run time
graphql_api.tests.test_repository.TestFetchRepository test_desc_commits_failed_ordering_on_test_results
Stack Traces | 0.333s run time
self = &lt;django.db.backends.utils.CursorWrapper object at 0x7f132ae62960&gt;
sql = 'INSERT INTO "reports_test" ("id", "external_id", "created_at", "updated_at", "repoid", "name", "testsuite", "flags_hash", "failure_rate", "commits_where_fail") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s::text[])'
params = ('plan', UUID('323d9d39-2b0e-45f6-8b4b-d7788f13fbc4'), datetime.datetime(2024, 8, 21, 18, 28, 5, 477746, tzinfo=datetime.timezone.utc), datetime.datetime(2024, 8, 21, 18, 28, 5, 477752, tzinfo=datetime.timezone.utc), 1799, 'cover', ...)
ignored_wrapper_args = (False, {'connection': &lt;DatabaseWrapper vendor='postgresql' alias='default'&gt;, 'cursor': &lt;django.db.backends.utils.CursorWrapper object at 0x7f132ae62960&gt;})

    def _execute(self, sql, params, *ignored_wrapper_args):
        self.db.validate_no_broken_transaction()
        with self.db.wrap_database_errors:
            if params is None:
                # params default might be backend specific.
                return self.cursor.execute(sql)
            else:
&gt;               return self.cursor.execute(sql, params)
E               psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "reports_test_pkey"
E               DETAIL:  Key (id)=(plan) already exists.

.../local/lib/python3.12.../db/backends/utils.py:89: UniqueViolation

The above exception was the direct cause of the following exception:

self = &lt;graphql_api.tests.test_repository.TestFetchRepository testMethod=test_desc_commits_failed_ordering_on_test_results&gt;

    def test_desc_commits_failed_ordering_on_test_results(self) -&gt; None:
        repo = RepositoryFactory(author=self.owner, active=True, private=True)
        test = TestFactory(repository=repo)
        _test_instance_1 = TestInstanceFactory(
            test=test,
            created_at=datetime.datetime.now(),
            repoid=repo.repoid,
            commitid="1",
        )
        _test_instance_2 = TestInstanceFactory(
            test=test,
            created_at=datetime.datetime.now(),
            repoid=repo.repoid,
            commitid="2",
        )
&gt;       test_2 = TestFactory(repository=repo)

graphql_api/tests/test_repository.py:933: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../local/lib/python3.12............/site-packages/factory/base.py:40: in __call__
    return cls.create(**kwargs)
.../local/lib/python3.12............/site-packages/factory/base.py:528: in create
    return cls._generate(enums.CREATE_STRATEGY, kwargs)
.../local/lib/python3.12....../site-packages/factory/django.py:117: in _generate
    return super()._generate(strategy, params)
.../local/lib/python3.12............/site-packages/factory/base.py:465: in _generate
    return step.build()
.../local/lib/python3.12.../site-packages/factory/builder.py:262: in build
    instance = self.factory_meta.instantiate(
.../local/lib/python3.12............/site-packages/factory/base.py:317: in instantiate
    return self.factory._create(model, *args, **kwargs)
.../local/lib/python3.12....../site-packages/factory/django.py:166: in _create
    return manager.create(*args, **kwargs)
.../local/lib/python3.12.../db/models/manager.py:87: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
.../local/lib/python3.12.../db/models/query.py:658: in create
    obj.save(force_insert=True, using=self.db)
.../local/lib/python3.12.../db/models/base.py:814: in save
    self.save_base(
.../local/lib/python3.12.../db/models/base.py:877: in save_base
    updated = self._save_table(
.../local/lib/python3.12.../db/models/base.py:1020: in _save_table
    results = self._do_insert(
.../local/lib/python3.12.../db/models/base.py:1061: in _do_insert
    return manager._insert(
.../local/lib/python3.12.../db/models/manager.py:87: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
.../local/lib/python3.12.../db/models/query.py:1805: in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
.../local/lib/python3.12.../models/sql/compiler.py:1822: in execute_sql
    cursor.execute(sql, params)
.../local/lib/python3.12.../integrations/django/__init__.py:641: in execute
    result = real_execute(self, sql, params)
.../local/lib/python3.12.../db/backends/utils.py:67: in execute
    return self._execute_with_wrappers(
.../local/lib/python3.12.../db/backends/utils.py:80: in _execute_with_wrappers
    return executor(sql, params, many, context)
.../local/lib/python3.12.../db/backends/utils.py:84: in _execute
    with self.db.wrap_database_errors:
.../local/lib/python3.12.../django/db/utils.py:91: in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = &lt;django.db.backends.utils.CursorWrapper object at 0x7f132ae62960&gt;
sql = 'INSERT INTO "reports_test" ("id", "external_id", "created_at", "updated_at", "repoid", "name", "testsuite", "flags_hash", "failure_rate", "commits_where_fail") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s::text[])'
params = ('plan', UUID('323d9d39-2b0e-45f6-8b4b-d7788f13fbc4'), datetime.datetime(2024, 8, 21, 18, 28, 5, 477746, tzinfo=datetime.timezone.utc), datetime.datetime(2024, 8, 21, 18, 28, 5, 477752, tzinfo=datetime.timezone.utc), 1799, 'cover', ...)
ignored_wrapper_args = (False, {'connection': &lt;DatabaseWrapper vendor='postgresql' alias='default'&gt;, 'cursor': &lt;django.db.backends.utils.CursorWrapper object at 0x7f132ae62960&gt;})

    def _execute(self, sql, params, *ignored_wrapper_args):
        self.db.validate_no_broken_transaction()
        with self.db.wrap_database_errors:
            if params is None:
                # params default might be backend specific.
                return self.cursor.execute(sql)
            else:
&gt;               return self.cursor.execute(sql, params)
E               django.db.utils.IntegrityError: duplicate key value violates unique constraint "reports_test_pkey"
E               DETAIL:  Key (id)=(plan) already exists.

.../local/lib/python3.12.../db/backends/utils.py:89: IntegrityError

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

Copy link

Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time.

❌ Failed Test Results:

Completed 2259 tests with 1 failed, 2252 passed and 6 skipped.

View the full list of failed tests

pytest

  • Class name: graphql_api.tests.test_repository.TestFetchRepository
    Test name: test_desc_commits_failed_ordering_on_test_results

    self = <django.db.backends.utils.CursorWrapper object at 0x7f132ae62960>
    sql = 'INSERT INTO "reports_test" ("id", "external_id", "created_at", "updated_at", "repoid", "name", "testsuite", "flags_hash", "failure_rate", "commits_where_fail") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s::text[])'
    params = ('plan', UUID('323d9d39-2b0e-45f6-8b4b-d7788f13fbc4'), datetime.datetime(2024, 8, 21, 18, 28, 5, 477746, tzinfo=datetime.timezone.utc), datetime.datetime(2024, 8, 21, 18, 28, 5, 477752, tzinfo=datetime.timezone.utc), 1799, 'cover', ...)
    ignored_wrapper_args = (False, {'connection': <DatabaseWrapper vendor='postgresql' alias='default'>, 'cursor': <django.db.backends.utils.CursorWrapper object at 0x7f132ae62960>})

    def _execute(self, sql, params, *ignored_wrapper_args):
    self.db.validate_no_broken_transaction()
    with self.db.wrap_database_errors:
    if params is None:
    # params default might be backend specific.
    return self.cursor.execute(sql)
    else:
    > return self.cursor.execute(sql, params)
    E psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "reports_test_pkey"
    E DETAIL: Key (id)=(plan) already exists.

    .../local/lib/python3.12.../db/backends/utils.py:89: UniqueViolation

    The above exception was the direct cause of the following exception:

    self = <graphql_api.tests.test_repository.TestFetchRepository testMethod=test_desc_commits_failed_ordering_on_test_results>

    def test_desc_commits_failed_ordering_on_test_results(self) -> None:
    repo = RepositoryFactory(author=self.owner, active=True, private=True)
    test = TestFactory(repository=repo)
    _test_instance_1 = TestInstanceFactory(
    test=test,
    created_at=datetime.datetime.now(),
    repoid=repo.repoid,
    commitid="1",
    )
    _test_instance_2 = TestInstanceFactory(
    test=test,
    created_at=datetime.datetime.now(),
    repoid=repo.repoid,
    commitid="2",
    )
    > test_2 = TestFactory(repository=repo)

    graphql_api/tests/test_repository.py:933:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    .../local/lib/python3.12............/site-packages/factory/base.py:40: in __call__
    return cls.create(**kwargs)
    .../local/lib/python3.12............/site-packages/factory/base.py:528: in create
    return cls._generate(enums.CREATE_STRATEGY, kwargs)
    .../local/lib/python3.12....../site-packages/factory/django.py:117: in _generate
    return super()._generate(strategy, params)
    .../local/lib/python3.12............/site-packages/factory/base.py:465: in _generate
    return step.build()
    .../local/lib/python3.12.../site-packages/factory/builder.py:262: in build
    instance = self.factory_meta.instantiate(
    .../local/lib/python3.12............/site-packages/factory/base.py:317: in instantiate
    return self.factory._create(model, *args, **kwargs)
    .../local/lib/python3.12....../site-packages/factory/django.py:166: in _create
    return manager.create(*args, **kwargs)
    .../local/lib/python3.12.../db/models/manager.py:87: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
    .../local/lib/python3.12.../db/models/query.py:658: in create
    obj.save(force_insert=True, using=self.db)
    .../local/lib/python3.12.../db/models/base.py:814: in save
    self.save_base(
    .../local/lib/python3.12.../db/models/base.py:877: in save_base
    updated = self._save_table(
    .../local/lib/python3.12.../db/models/base.py:1020: in _save_table
    results = self._do_insert(
    .../local/lib/python3.12.../db/models/base.py:1061: in _do_insert
    return manager._insert(
    .../local/lib/python3.12.../db/models/manager.py:87: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
    .../local/lib/python3.12.../db/models/query.py:1805: in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
    .../local/lib/python3.12.../models/sql/compiler.py:1822: in execute_sql
    cursor.execute(sql, params)
    .../local/lib/python3.12.../integrations/django/__init__.py:641: in execute
    result = real_execute(self, sql, params)
    .../local/lib/python3.12.../db/backends/utils.py:67: in execute
    return self._execute_with_wrappers(
    .../local/lib/python3.12.../db/backends/utils.py:80: in _execute_with_wrappers
    return executor(sql, params, many, context)
    .../local/lib/python3.12.../db/backends/utils.py:84: in _execute
    with self.db.wrap_database_errors:
    .../local/lib/python3.12.../django/db/utils.py:91: in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    self = <django.db.backends.utils.CursorWrapper object at 0x7f132ae62960>
    sql = 'INSERT INTO "reports_test" ("id", "external_id", "created_at", "updated_at", "repoid", "name", "testsuite", "flags_hash", "failure_rate", "commits_where_fail") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s::text[])'
    params = ('plan', UUID('323d9d39-2b0e-45f6-8b4b-d7788f13fbc4'), datetime.datetime(2024, 8, 21, 18, 28, 5, 477746, tzinfo=datetime.timezone.utc), datetime.datetime(2024, 8, 21, 18, 28, 5, 477752, tzinfo=datetime.timezone.utc), 1799, 'cover', ...)
    ignored_wrapper_args = (False, {'connection': <DatabaseWrapper vendor='postgresql' alias='default'>, 'cursor': <django.db.backends.utils.CursorWrapper object at 0x7f132ae62960>})

    def _execute(self, sql, params, *ignored_wrapper_args):
    self.db.validate_no_broken_transaction()
    with self.db.wrap_database_errors:
    if params is None:
    # params default might be backend specific.
    return self.cursor.execute(sql)
    else:
    > return self.cursor.execute(sql, params)
    E django.db.utils.IntegrityError: duplicate key value violates unique constraint "reports_test_pkey"
    E DETAIL: Key (id)=(plan) already exists.

    .../local/lib/python3.12.../db/backends/utils.py:89: IntegrityError

@michelletran-codecov michelletran-codecov added this pull request to the merge queue Aug 22, 2024
Merged via the queue into main with commit fab34b5 Aug 22, 2024
18 checks passed
@michelletran-codecov michelletran-codecov deleted the 709_strip_trailing_slashes branch August 22, 2024 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants