D2833: tests: teach get-with-headers.py to ignore dynamic headers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

D2833: tests: teach get-with-headers.py to ignore dynamic headers

indygreg (Gregory Szorc)
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The Date and Server HTTP headers are dynamic by nature. They are
  also present on every response and are mostly advisory.
 
  It isn't important for us to test for the presence of these
  headers. In fact, all tests currently glob over the entirety
  of their values.
 
  Having to constantly glob these headers feels like more trouble
  than it is worth. Let's teach get-with-headers.py to hide them
  by default.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2833

AFFECTED FILES
  tests/get-with-headers.py
  tests/test-archive.t
  tests/test-hgweb-commands.t
  tests/test-http-protocol.t

CHANGE DETAILS

diff --git a/tests/test-http-protocol.t b/tests/test-http-protocol.t
--- a/tests/test-http-protocol.t
+++ b/tests/test-http-protocol.t
@@ -49,42 +49,32 @@
   $ get-with-headers.py --headeronly $LOCALIP:$HGPORT '?cmd=getbundle&heads=e93700bd72895c5addab234c56d4024b487a362f&common=0000000000000000000000000000000000000000' -
   200 Script output follows
   content-type: application/mercurial-0.1
-  date: * (glob)
-  server: * (glob)
   transfer-encoding: chunked
 
 Server should send application/mercurial-0.1 when client says it wants it
 
   $ get-with-headers.py --hgproto '0.1' --headeronly $LOCALIP:$HGPORT '?cmd=getbundle&heads=e93700bd72895c5addab234c56d4024b487a362f&common=0000000000000000000000000000000000000000' -
   200 Script output follows
   content-type: application/mercurial-0.1
-  date: * (glob)
-  server: * (glob)
   transfer-encoding: chunked
 
 Server should send application/mercurial-0.2 when client says it wants it
 
   $ get-with-headers.py --hgproto '0.2' --headeronly $LOCALIP:$HGPORT '?cmd=getbundle&heads=e93700bd72895c5addab234c56d4024b487a362f&common=0000000000000000000000000000000000000000' -
   200 Script output follows
   content-type: application/mercurial-0.2
-  date: * (glob)
-  server: * (glob)
   transfer-encoding: chunked
 
   $ get-with-headers.py --hgproto '0.1 0.2' --headeronly $LOCALIP:$HGPORT '?cmd=getbundle&heads=e93700bd72895c5addab234c56d4024b487a362f&common=0000000000000000000000000000000000000000' -
   200 Script output follows
   content-type: application/mercurial-0.2
-  date: * (glob)
-  server: * (glob)
   transfer-encoding: chunked
 
 Requesting a compression format that server doesn't support results will fall back to 0.1
 
   $ get-with-headers.py --hgproto '0.2 comp=aa' --headeronly $LOCALIP:$HGPORT '?cmd=getbundle&heads=e93700bd72895c5addab234c56d4024b487a362f&common=0000000000000000000000000000000000000000' -
   200 Script output follows
   content-type: application/mercurial-0.1
-  date: * (glob)
-  server: * (glob)
   transfer-encoding: chunked
 
 #if zstd
@@ -105,8 +95,6 @@
   200 Script output follows
   content-length: 41
   content-type: application/mercurial-0.1
-  date: * (glob)
-  server: * (glob)
   
   e93700bd72895c5addab234c56d4024b487a362f
 
diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t
+++ b/tests/test-hgweb-commands.t
@@ -1922,8 +1922,6 @@
   404 Not Found
   content-length: 12
   content-type: application/mercurial-0.1
-  date: * (glob)
-  server: * (glob)
   
   0
   Not Found
diff --git a/tests/test-archive.t b/tests/test-archive.t
--- a/tests/test-archive.t
+++ b/tests/test-archive.t
@@ -126,82 +126,64 @@
   200 Script output follows
   content-disposition: attachment; filename=test-archive-1701ef1f1510.tar.gz
   content-type: application/x-gzip
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=408, sha1=8fa06531bddecc365a9f5edb0f88b65974bfe505
   % tar.bz2 and zip disallowed should both give 403
   403 Archive type not allowed: bz2
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1451, sha1=4c5cf0f574446c44feb7f88f4e0e2a56bd92c352
   403 Archive type not allowed: zip
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1451, sha1=cbfa5574b337348bfd0564cc534474d002e7d6c7
   $ test_archtype bz2 tar.bz2 zip tar.gz
   % bz2 allowed should give 200
   200 Script output follows
   content-disposition: attachment; filename=test-archive-1701ef1f1510.tar.bz2
   content-type: application/x-bzip2
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=426, sha1=8d87f5aba6e14f1bfea6c232985982c278b2fb0b
   % zip and tar.gz disallowed should both give 403
   403 Archive type not allowed: zip
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1451, sha1=cbfa5574b337348bfd0564cc534474d002e7d6c7
   403 Archive type not allowed: gz
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1450, sha1=71f0b12d59f85fdcfe8ff493e2dc66863f2f7734
   $ test_archtype zip zip tar.gz tar.bz2
   % zip allowed should give 200
   200 Script output follows
   content-disposition: attachment; filename=test-archive-1701ef1f1510.zip
   content-type: application/zip
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1377, sha1=677b14d3d048778d5eb5552c14a67e6192068650
   % tar.gz and tar.bz2 disallowed should both give 403
   403 Archive type not allowed: gz
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1450, sha1=71f0b12d59f85fdcfe8ff493e2dc66863f2f7734
   403 Archive type not allowed: bz2
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1451, sha1=4c5cf0f574446c44feb7f88f4e0e2a56bd92c352
@@ -213,82 +195,64 @@
   200 Script output follows
   content-disposition: attachment; filename=test-archive-1701ef1f1510.tar.gz
   content-type: application/x-gzip
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=408, sha1=8fa06531bddecc365a9f5edb0f88b65974bfe505
   % tar.bz2 and zip disallowed should both give 403
   403 Archive type not allowed: bz2
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1451, sha1=4c5cf0f574446c44feb7f88f4e0e2a56bd92c352
   403 Archive type not allowed: zip
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1451, sha1=cbfa5574b337348bfd0564cc534474d002e7d6c7
   $ test_archtype_deprecated bz2 tar.bz2 zip tar.gz
   % bz2 allowed should give 200
   200 Script output follows
   content-disposition: attachment; filename=test-archive-1701ef1f1510.tar.bz2
   content-type: application/x-bzip2
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=426, sha1=8d87f5aba6e14f1bfea6c232985982c278b2fb0b
   % zip and tar.gz disallowed should both give 403
   403 Archive type not allowed: zip
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1451, sha1=cbfa5574b337348bfd0564cc534474d002e7d6c7
   403 Archive type not allowed: gz
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1450, sha1=71f0b12d59f85fdcfe8ff493e2dc66863f2f7734
   $ test_archtype_deprecated zip zip tar.gz tar.bz2
   % zip allowed should give 200
   200 Script output follows
   content-disposition: attachment; filename=test-archive-1701ef1f1510.zip
   content-type: application/zip
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1377, sha1=677b14d3d048778d5eb5552c14a67e6192068650
   % tar.gz and tar.bz2 disallowed should both give 403
   403 Archive type not allowed: gz
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1450, sha1=71f0b12d59f85fdcfe8ff493e2dc66863f2f7734
   403 Archive type not allowed: bz2
   content-type: text/html; charset=ascii
-  date: * (glob)
   etag: W/"*" (glob)
-  server: * (glob)
   transfer-encoding: chunked
   
   body: size=1451, sha1=4c5cf0f574446c44feb7f88f4e0e2a56bd92c352
diff --git a/tests/get-with-headers.py b/tests/get-with-headers.py
--- a/tests/get-with-headers.py
+++ b/tests/get-with-headers.py
@@ -35,6 +35,8 @@
                          'value is <header>=<value>')
 parser.add_argument('--bodyfile',
                     help='Write HTTP response body to a file')
+parser.add_argument('--showdynamicheaders', action='store_true',
+                    help='Show dynamic headers that are hidden by default')
 parser.add_argument('host')
 parser.add_argument('path')
 parser.add_argument('show', nargs='*')
@@ -69,6 +71,10 @@
     if show[:1] == ['-']:
         show = sorted(h for h, v in response.getheaders()
                       if h.lower() not in show)
+
+        if not args.showdynamicheaders:
+            show = [h for h in show if h.lower() not in ('date', 'server')]
+
     for h in [h.lower() for h in show]:
         if response.getheader(h, None) is not None:
             stdout.write(b"%s: %s\n" % (h.encode('ascii'),



To: indygreg, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

D2833: tests: teach get-with-headers.py to ignore dynamic headers

indygreg (Gregory Szorc)
mharbison72 added a comment.


  I’ve got a patch locally that will pattern substitute away the date.  It’s been useful for LFS, because I’ve been debug dumping the headers and JSON on the client side.  I’ll try to submit that tonight.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2833

To: indygreg, #hg-reviewers
Cc: mharbison72, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

D2833: tests: teach get-with-headers.py to ignore dynamic headers

indygreg (Gregory Szorc)
In reply to this post by indygreg (Gregory Szorc)
indygreg abandoned this revision.
indygreg added a comment.


  I like Matt's patch and will do something more deterministic.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2833

To: indygreg, #hg-reviewers
Cc: mharbison72, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel