Make HTTP artifact MIME test deterministic
This commit is contained in:
@@ -3,7 +3,6 @@ package httpadapter
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"mime"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -14,7 +13,7 @@ import (
|
|||||||
func TestRestrictedArtifactReaderReadsContainedFiles(t *testing.T) {
|
func TestRestrictedArtifactReaderReadsContainedFiles(t *testing.T) {
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
outside := t.TempDir()
|
outside := t.TempDir()
|
||||||
inputPath := filepath.Join(root, "input.md")
|
inputPath := filepath.Join(root, "input.html")
|
||||||
if err := os.WriteFile(inputPath, []byte("allowed"), 0o644); err != nil {
|
if err := os.WriteFile(inputPath, []byte("allowed"), 0o644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -34,17 +33,17 @@ func TestRestrictedArtifactReaderReadsContainedFiles(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, ref := range []scriptorium.ArtifactRef{
|
for _, ref := range []scriptorium.ArtifactRef{
|
||||||
{Type: scriptorium.ArtifactRefFile, URI: "nested/../input.md"},
|
{Type: scriptorium.ArtifactRefFile, URI: "nested/../input.html"},
|
||||||
{Type: scriptorium.ArtifactRefFile, URI: inputPath},
|
{Type: scriptorium.ArtifactRefFile, URI: inputPath},
|
||||||
} {
|
} {
|
||||||
artifact, err := reader.Read(context.Background(), ref)
|
artifact, err := reader.Read(context.Background(), ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("read contained path %q: %v", ref.URI, err)
|
t.Fatalf("read contained path %q: %v", ref.URI, err)
|
||||||
}
|
}
|
||||||
if artifact.Name != "input.md" || artifact.URI != inputPath || artifact.Size != int64(len("allowed")) || string(artifact.Body) != "allowed" {
|
if artifact.Name != "input.html" || artifact.URI != inputPath || artifact.Size != int64(len("allowed")) || string(artifact.Body) != "allowed" {
|
||||||
t.Fatalf("unexpected artifact metadata: %#v", artifact)
|
t.Fatalf("unexpected artifact metadata: %#v", artifact)
|
||||||
}
|
}
|
||||||
if artifact.ContentType != mime.TypeByExtension(".md") {
|
if artifact.ContentType != "text/html; charset=utf-8" {
|
||||||
t.Fatalf("unexpected artifact content type: %q", artifact.ContentType)
|
t.Fatalf("unexpected artifact content type: %q", artifact.ContentType)
|
||||||
}
|
}
|
||||||
if artifact.Hash != artifactHash([]byte("allowed")) {
|
if artifact.Hash != artifactHash([]byte("allowed")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user