properly handle no vmod hash/blobdigest support

parent 3d30f996
...@@ -10,6 +10,12 @@ vmod_get_h_SOURCES = \ ...@@ -10,6 +10,12 @@ vmod_get_h_SOURCES = \
vmod_get_h_LDADD = -ldl vmod_get_h_LDADD = -ldl
TESTS = \
vtc/plain.vtc \
vtc/name_hash.vtc \
vtc/expires.vtc \
vtc/done.vtc
# ---------------------------------------- # ----------------------------------------
# ext vmods # ext vmods
...@@ -18,8 +24,15 @@ vmod_blob.h: vmod_get_h $(VMOD_BLOB) ...@@ -18,8 +24,15 @@ vmod_blob.h: vmod_get_h $(VMOD_BLOB)
$(builddir)/vmod_get_h blob $(VMOD_BLOB) >$@ $(builddir)/vmod_get_h blob $(VMOD_BLOB) >$@
vmod_blobdigest.h: vmod_get_h $(VMOD_BLOBDIGEST) vmod_blobdigest.h: vmod_get_h $(VMOD_BLOBDIGEST)
$(builddir)/vmod_get_h blobdigest $(VMOD_BLOBDIGEST) >$@ $(builddir)/vmod_get_h blobdigest $(VMOD_BLOBDIGEST) >$@
libvmod_tus_la_SOURCES = tus_blob.c
tus_blob.c: vmod_blob.h vmod_blobdigest.h tus_blob.c: vmod_blob.h vmod_blobdigest.h
AM_CFLAGS += -DHAVE_CHKSUM=1 TESTS += \
vtc/chksum/plain.vtc \
vtc/chksum/name_hash.vtc \
vtc/chksum/done.vtc
else
libvmod_tus_la_SOURCES = tus_blob_stub.c
endif endif
# ---------------------------------------- # ----------------------------------------
...@@ -28,11 +41,10 @@ endif ...@@ -28,11 +41,10 @@ endif
vmod_LTLIBRARIES = \ vmod_LTLIBRARIES = \
libvmod_tus.la libvmod_tus.la
libvmod_tus_la_SOURCES = \ libvmod_tus_la_SOURCES += \
tbl_hash_enum.h \ tbl_hash_enum.h \
tbl_method.h \ tbl_method.h \
tus_b64.h \ tus_b64.h \
tus_blob.c \
tus_blob.h \ tus_blob.h \
tus_checksums.h \ tus_checksums.h \
tus_concat.h \ tus_concat.h \
...@@ -79,12 +91,6 @@ AM_VTC_LOG_FLAGS = \ ...@@ -79,12 +91,6 @@ AM_VTC_LOG_FLAGS = \
-p vcl_path="$(abs_top_srcdir)/vcl:$(VARNISHAPI_VCLDIR)" \ -p vcl_path="$(abs_top_srcdir)/vcl:$(VARNISHAPI_VCLDIR)" \
-p vmod_path="$(abs_builddir)/.libs:$(vmoddir):$(VARNISHAPI_VMODDIR)" -p vmod_path="$(abs_builddir)/.libs:$(vmoddir):$(VARNISHAPI_VMODDIR)"
TESTS = \
vtc/plain.vtc \
vtc/name_hash.vtc \
vtc/expires.vtc \
vtc/done.vtc
# Documentation # Documentation
dist_doc_DATA = \ dist_doc_DATA = \
......
/*-
* Copyright 2020 UPLEX Nils Goroll Systemoptimierung
* All rights reserved.
*
* Author: Nils Goroll <nils.goroll@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "config.h"
#include "cache/cache.h"
#include "vsb.h"
#include "tus_blob.h"
#include "tus_checksums.h"
int
tus_chksum_init(VRT_CTX) {
(void) ctx;
return (0);
}
int
tus_chksum_fini(VRT_CTX) {
(void) ctx;
return (0);
}
/* ------------------------------------------------------------
* wrap base64
*/
VCL_BLOB
tus_b64_decode(VRT_CTX, const char *s, VCL_INT l)
{
(void) s;
(void) l;
VRT_fail(ctx, "base64 decode support not available - "
"vmod_blob support not compiled in");
return (NULL);
}
/* ------------------------------------------------------------
* enabled checksums
*/
const char *
tus_checksums(void)
{
return (NULL);
}
/* ------------------------------------------------------------
* handling of tus checksums
*/
/* tus hash names to blobdiget object */
struct vmod_blobdigest_digest *
tus_hash(const char *s, size_t l)
{
(void) s;
(void) l;
return (NULL);
}
struct tus_chksum *
tus_chksum_new(VRT_CTX, struct vmod_blobdigest_digest *d)
{
(void) ctx;
(void) d;
return (NULL);
}
struct tus_chksum *
tus_chksum_hdr(VRT_CTX, const char *hdr)
{
(void) ctx;
(void) hdr;
return (NULL);
}
void
tus_chksum_update(VRT_CTX, struct tus_chksum *c,
const void *ptr, size_t l)
{
(void) ctx;
(void) c;
(void) ptr;
(void) l;
INCOMPL();
}
VCL_BLOB
tus_chksum_final(VRT_CTX, struct tus_chksum *c)
{
(void) ctx;
(void) c;
INCOMPL();
return (NULL);
}
VCL_BOOL
tus_chksum_equal(VRT_CTX, struct tus_chksum *c)
{
(void) tus_chksum_final(ctx, c);
return (0);
}
/* tus_blob.c */
const char * tus_checksums(void);
varnishtest "test vmod-tus set done redirect"
server s1 {
rxreq
txresp
expect req.method == PUT
expect req.bodylen == 386550
} -start
varnish v1 -vcl+backend {
import blob;
import blobdigest;
import tus;
sub vcl_init {
new tmp = tus.server("http://localhost",
basedir="/tmp/tus", max = 4MB);
}
sub vcl_backend_fetch {
if (bereq.url ~ "^/id") {
set bereq.backend = s1;
} else {
return (abandon);
}
}
sub vcl_recv {
if (tmp.recv(id=req.http.id)) {
return(pass);
} else {
return(synth(4200));
}
}
sub vcl_synth {
if (resp.status == 4200) {
tmp.synth();
return (deliver);
}
}
sub vcl_deliver {
tmp.deliver();
tmp.done(req.url);
}
} -start
# dynamic file name complete post
client c1 {
txreq -method "DELETE" -url "/id" \
-hdr "Tus-Resumable: 1.0.0"
rxresp
txreq -method POST \
-hdr "Upload-Length: 386550" \
-hdr "Tus-Resumable: 1.0.0" \
-hdr "Content-Type: application/offset+octet-stream" \
-hdr "Id: id" \
-nolen -hdr "Transfer-Encoding: chunked"
chunkedlen 8192
chunkedlen 4096
chunkedlen 4096
chunkedlen 16384
chunkedlen 16384
chunkedlen 16384
chunkedlen 321014
chunkedlen 0
rxresp
expect resp.status == 201
expect resp.http.Tus-Resumable == "1.0.0"
expect resp.http.Tus-Version == "1.0.0"
expect resp.http.Tus-Extension == "creation,creation-with-upload,expiration,termination,concatenation,checksum"
expect resp.http.Tus-Checksum-Algorithm == "crc32,icrc32,md5,rs,sha1,sha224,sha256,sha384,sha3_224,sha3_256,sha3_384,sha3_512,sha512"
expect resp.http.Tus-Max-Size == 4194304
expect resp.http.Upload-Offset == 386550
expect resp.http.Upload-Length == 386550
expect resp.http.Upload-Expires ~ "GMT$"
expect resp.http.Location == "http://localhost/id"
# even for a done file, HEAD will return the correct metadata
txreq -method HEAD -url "/id" \
-hdr "Tus-Resumable: 1.0.0"
rxresp
expect resp.status == 200
expect resp.http.Tus-Resumable == "1.0.0"
expect resp.http.Tus-Version == "1.0.0"
expect resp.http.Tus-Extension == "creation,creation-with-upload,expiration,termination,concatenation,checksum"
expect resp.http.Tus-Checksum-Algorithm == "crc32,icrc32,md5,rs,sha1,sha224,sha256,sha384,sha3_224,sha3_256,sha3_384,sha3_512,sha512"
expect resp.http.Tus-Max-Size == 4194304
expect resp.http.Upload-Offset == 386550
expect resp.http.Upload-Length == 386550
expect resp.http.Upload-Expires ~ "GMT$"
expect resp.http.Content-Location == "http://localhost/id"
txreq -url "/id" \
-hdr "Tus-Resumable: 1.0.0"
rxresp
expect resp.status == 301
expect resp.http.Location == "http://localhost/id"
} -run
This diff is collapsed.
This diff is collapsed.
...@@ -8,9 +8,6 @@ server s1 { ...@@ -8,9 +8,6 @@ server s1 {
} -start } -start
varnish v1 -vcl+backend { varnish v1 -vcl+backend {
import blob;
import blobdigest;
import tus; import tus;
sub vcl_init { sub vcl_init {
...@@ -68,8 +65,8 @@ client c1 { ...@@ -68,8 +65,8 @@ client c1 {
expect resp.status == 201 expect resp.status == 201
expect resp.http.Tus-Resumable == "1.0.0" expect resp.http.Tus-Resumable == "1.0.0"
expect resp.http.Tus-Version == "1.0.0" expect resp.http.Tus-Version == "1.0.0"
expect resp.http.Tus-Extension == "creation,creation-with-upload,expiration,termination,concatenation,checksum" expect resp.http.Tus-Extension == "creation,creation-with-upload,expiration,termination,concatenation"
expect resp.http.Tus-Checksum-Algorithm == "crc32,icrc32,md5,rs,sha1,sha224,sha256,sha384,sha3_224,sha3_256,sha3_384,sha3_512,sha512" expect resp.http.Tus-Checksum-Algorithm == <undef>
expect resp.http.Tus-Max-Size == 4194304 expect resp.http.Tus-Max-Size == 4194304
expect resp.http.Upload-Offset == 386550 expect resp.http.Upload-Offset == 386550
expect resp.http.Upload-Length == 386550 expect resp.http.Upload-Length == 386550
...@@ -83,8 +80,8 @@ client c1 { ...@@ -83,8 +80,8 @@ client c1 {
expect resp.status == 200 expect resp.status == 200
expect resp.http.Tus-Resumable == "1.0.0" expect resp.http.Tus-Resumable == "1.0.0"
expect resp.http.Tus-Version == "1.0.0" expect resp.http.Tus-Version == "1.0.0"
expect resp.http.Tus-Extension == "creation,creation-with-upload,expiration,termination,concatenation,checksum" expect resp.http.Tus-Extension == "creation,creation-with-upload,expiration,termination,concatenation"
expect resp.http.Tus-Checksum-Algorithm == "crc32,icrc32,md5,rs,sha1,sha224,sha256,sha384,sha3_224,sha3_256,sha3_384,sha3_512,sha512" expect resp.http.Tus-Checksum-Algorithm == <undef>
expect resp.http.Tus-Max-Size == 4194304 expect resp.http.Tus-Max-Size == 4194304
expect resp.http.Upload-Offset == 386550 expect resp.http.Upload-Offset == 386550
expect resp.http.Upload-Length == 386550 expect resp.http.Upload-Length == 386550
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment