You are here

public function AuthcacheVarnishTestCase::testRequestValidation in Authenticated User Page Caching (Authcache) 7.2

Cover authcache_varnish_request_validate().

File

modules/authcache_varnish/authcache_varnish.test, line 231
Test cases for authcache_varnish module.

Class

AuthcacheVarnishTestCase
Cover authcache_varnish module.

Code

public function testRequestValidation() {
  variable_set('authcache_varnish_validate_reverse_proxy_address', FALSE);
  variable_set('authcache_roles', array(
    DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID,
  ));
  variable_set('page_cache_maximum_age', 3600);
  $this
    ->drupalGet('authcache-varnish-get-key');
  $this
    ->assertResponse(403, 'Deny access to get-key-callback when X-Varnish header is not on the request');
  $this
    ->drupalGet('authcache-varnish-get-key', array(), array(
    'X-Varnish: 123',
  ));
  $this
    ->assertResponse(200, 'Grant access to get-key-callback when X-Varnish header is on the request');
  $this
    ->drupalGet('<front>');
  $this
    ->assertNoVary('X-Authcache-Key');
  $this
    ->assertCacheControl('must-revalidate');
  $this
    ->assertCacheControl('no-cache');
  $this
    ->assertNoCacheControl('public');
  $this
    ->drupalGet('<front>', array(), array(
    'X-Varnish: 123',
  ));
  $this
    ->assertVary('X-Authcache-Key');
  $this
    ->assertCacheControl('public');
  $this
    ->assertCacheControl('max-age=3600');
  $this
    ->assertNoCacheControl('must-revalidate');
  $this
    ->assertNoCacheControl('no-cache');
  variable_set('authcache_varnish_header', 'HTTP_X_CUSTOM_HEADER');
  $this
    ->drupalGet('authcache-varnish-get-key');
  $this
    ->assertResponse(403, 'Deny access to get-key-callback when X-Custom-Header header is not on the request');
  $this
    ->drupalGet('authcache-varnish-get-key', array(), array(
    'X-Custom-Header: 123',
  ));
  $this
    ->assertResponse(200, 'Grant access to get-key-callback when X-Custom-Header header is on the request');
  $this
    ->drupalGet('<front>');
  $this
    ->assertNoVary('X-Authcache-Key');
  $this
    ->assertCacheControl('must-revalidate');
  $this
    ->assertCacheControl('no-cache');
  $this
    ->assertNoCacheControl('public');
  $this
    ->drupalGet('<front>', array(), array(
    'X-Custom-Header: 123',
  ));
  $this
    ->assertVary('X-Authcache-Key');
  $this
    ->assertCacheControl('public');
  $this
    ->assertCacheControl('max-age=3600');
  $this
    ->assertNoCacheControl('must-revalidate');
  $this
    ->assertNoCacheControl('no-cache');
}