Problem/Motivation

Within the Penn State repository for this module, there are a number of kernel tests that should add near to full automated test coverage.

The intention here is to lift and shift as many as possible, but not quite all of them. Some of the tests are covering functionality that doesn't exist here (yet).

Note - in order to test invalidation chunking, the purger had to override the ideal conditions limit to allow > 100 invalidations per web request. I'm not sure what the best value for this would actually be.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

luke.leber created an issue. See original summary.

luke.leber’s picture

Issue summary: View changes
luke.leber’s picture

Issue summary: View changes
luke.leber’s picture

Issue summary: View changes
luke.leber’s picture

Status: Active » Needs review

Alright, this is a decent start. The test cases that were omitted were...

  /**
   * Test case for overflow protection (almost overflowing).
   */
  public function testGetValueAlmostOverflowing() {
    $cloudflare_tags_header = $this->purgeTagsHeaders->current();
    static::assertInstanceOf(CloudflareTagsHeader::class, $cloudflare_tags_header);

    $this->config('cloudflare_purger.settings')
      ->set('max_response_header_length', 8192)
      ->save();

    // Run it right up to the brink. The breakdown of 1168 tags is 7008 hash
    // characters, plus 1167 comma characters, plus 12 characters for the
    // header name for a total of 8187 bytes.
    $tags = array_fill(0, 1168, 'test');

    $this->mockLoggerChannel
      ->expects(static::never())
      ->method('warning');

    // 1168 tags should yield 8175 bytes.
    static::assertSame(
      8175,
      strlen($cloudflare_tags_header->getValue($tags))
    );
  }

  /**
   * Test case for overflow protection (with slight overflow).
   */
  public function testGetValueSlightlyOverflowing() {

    $cloudflare_tags_header = $this->purgeTagsHeaders->current();
    static::assertInstanceOf(CloudflareTagsHeader::class, $cloudflare_tags_header);

    $this->config('cloudflare_purger.settings')
      ->set('max_response_header_length', 8192)
      ->save();

    // Run it right up to the brink. The breakdown of 1169 tags is 7014 hash
    // characters, plus 1168 comma characters, plus 12 characters for the
    // header name for a total of 8194 bytes.
    $tags = array_fill(0, 1169, 'test');

    $this->mockLoggerChannel
      ->expects(static::once())
      ->method('warning')
      ->with(
        'A response header was projected to exceed the configured limit by %amount tags. This may prevent content from purging properly.',
        ['%amount' => 1]
      );

    // The header value should be truncated to stay within the limit.
    static::assertSame(
      8175,
      strlen($cloudflare_tags_header->getValue($tags))
    );
  }

  /**
   * Test case for overflow protection (with gross overflow).
   */
  public function testGetValueGrosslyOverflowing() {

    $cloudflare_tags_header = $this->purgeTagsHeaders->current();
    static::assertInstanceOf(CloudflareTagsHeader::class, $cloudflare_tags_header);

    $this->config('cloudflare_purger.settings')
      ->set('max_response_header_length', 8192)
      ->save();

    // Run it right up to the brink. The breakdown of 2000 tags is 12000 hash
    // characters, plus 1999 comma characters, plus 12 characters for the
    // header name for a total of 14011 bytes.
    $tags = array_fill(0, 2000, 'test');

    $this->mockLoggerChannel
      ->expects(static::once())
      ->method('warning')
      ->with(
        'A response header was projected to exceed the configured limit by %amount tags. This may prevent content from purging properly.',
        ['%amount' => 832]
      );

    // The header value should be truncated to stay within the limit.
    static::assertSame(
      8175,
      strlen($cloudflare_tags_header->getValue($tags))
    );
  }

which really only make sense when there's a response header protection in place (another MR to come).

luke.leber’s picture

Assigned: luke.leber » Unassigned
bkosborne’s picture

Status: Needs review » Fixed

Looks good to me. There's nothing testing the other invalidation methods like "everything" and "url" but I think that's fine for now (I also am unsure if we should even support the everything method).

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.