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