-
-
Notifications
You must be signed in to change notification settings - Fork 744
Expand file tree
/
Copy pathcdv_test.go
More file actions
128 lines (124 loc) · 3.66 KB
/
cdv_test.go
File metadata and controls
128 lines (124 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package httpheaders_test
import (
"testing"
"github.com/imgproxy/imgproxy/v4/httpheaders"
"github.com/stretchr/testify/require"
)
func TestContentDispositionValue(t *testing.T) {
// Test cases for ContentDispositionValue function that generates content-disposition headers
tests := []struct {
name string
url string
filename string
ext string
returnAttachment bool
expected string
contentType string
}{
{
name: "BasicURL",
url: "http://example.com/test.jpg",
filename: "",
ext: "",
contentType: "",
returnAttachment: false,
expected: "inline; filename=\"test.jpg\"",
},
{
name: "EmptyFilename",
url: "http://example.com/path/to/",
filename: "",
ext: "",
contentType: "",
returnAttachment: false,
expected: "inline; filename=\"image\"",
},
{
name: "EmptyFilenameWithExt",
url: "http://example.com/path/to/",
filename: "",
ext: ".png",
contentType: "",
returnAttachment: false,
expected: "inline; filename=\"image.png\"",
},
{
name: "EmptyFilenameWithFilenameAndExt",
url: "http://example.com/path/to/",
filename: "example",
ext: ".png",
contentType: "",
returnAttachment: false,
expected: "inline; filename=\"example.png\"",
},
{
name: "EmptyFilenameWithFilenameOverride",
url: "http://example.com/path/to/",
filename: "example",
ext: ".jpg",
contentType: "",
returnAttachment: false,
expected: "inline; filename=\"example.jpg\"",
},
{
name: "PresentFilenameWithExtOverride",
url: "http://example.com/path/to/face.png",
filename: "",
ext: ".jpg",
contentType: "",
returnAttachment: false,
expected: "inline; filename=\"face.jpg\"",
},
{
name: "PresentFilenameWithFilenameOverride",
url: "http://example.com/path/to/123.png",
filename: "face",
ext: ".jpg",
contentType: "",
returnAttachment: false,
expected: "inline; filename=\"face.jpg\"",
},
{
name: "EmptyFilenameWithFallback",
url: "http://example.com/path/to/",
filename: "",
ext: ".png",
contentType: "",
returnAttachment: false,
expected: "inline; filename=\"image.png\"",
},
{
name: "AttachmentDisposition",
url: "http://example.com/test.jpg",
filename: "",
ext: "",
contentType: "",
returnAttachment: true,
expected: "attachment; filename=\"test.jpg\"",
},
{
name: "FilenameWithQuotes",
url: "http://example.com/test.jpg",
filename: "my\"file",
ext: ".png",
returnAttachment: false,
contentType: "",
expected: "inline; filename=\"my%22file.png\"",
},
{
name: "FilenameWithContentType",
url: "http://example.com/test",
filename: "my\"file",
ext: "",
contentType: "image/png",
returnAttachment: false,
expected: "inline; filename=\"my%22file.png\"",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
result := httpheaders.ContentDispositionValue(tc.url, tc.filename, tc.ext, tc.contentType, tc.returnAttachment)
require.Equal(t, tc.expected, result)
})
}
}