processing_options_test.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. package main
  2. import (
  3. "context"
  4. "encoding/base64"
  5. "fmt"
  6. "net/http"
  7. "net/url"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/require"
  11. "github.com/stretchr/testify/suite"
  12. )
  13. type ProcessingOptionsTestSuite struct{ MainTestSuite }
  14. func (s *ProcessingOptionsTestSuite) getRequest(url string) *http.Request {
  15. req, _ := http.NewRequest("GET", url, nil)
  16. return req
  17. }
  18. func (s *ProcessingOptionsTestSuite) TestParseBase64URL() {
  19. imageURL := "http://images.dev/lorem/ipsum.jpg?param=value"
  20. req := s.getRequest(fmt.Sprintf("http://example.com/unsafe/size:100:100/%s.png", base64.RawURLEncoding.EncodeToString([]byte(imageURL))))
  21. ctx, err := parsePath(context.Background(), req)
  22. require.Nil(s.T(), err)
  23. assert.Equal(s.T(), imageURL, getImageURL(ctx))
  24. assert.Equal(s.T(), imageTypePNG, getProcessingOptions(ctx).Format)
  25. }
  26. func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithoutExtension() {
  27. imageURL := "http://images.dev/lorem/ipsum.jpg?param=value"
  28. req := s.getRequest(fmt.Sprintf("http://example.com/unsafe/size:100:100/%s", base64.RawURLEncoding.EncodeToString([]byte(imageURL))))
  29. ctx, err := parsePath(context.Background(), req)
  30. require.Nil(s.T(), err)
  31. assert.Equal(s.T(), imageURL, getImageURL(ctx))
  32. assert.Equal(s.T(), imageTypeJPEG, getProcessingOptions(ctx).Format)
  33. }
  34. func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithBase() {
  35. conf.BaseURL = "http://images.dev/"
  36. imageURL := "lorem/ipsum.jpg?param=value"
  37. req := s.getRequest(fmt.Sprintf("http://example.com/unsafe/size:100:100/%s.png", base64.RawURLEncoding.EncodeToString([]byte(imageURL))))
  38. ctx, err := parsePath(context.Background(), req)
  39. require.Nil(s.T(), err)
  40. assert.Equal(s.T(), fmt.Sprintf("%s%s", conf.BaseURL, imageURL), getImageURL(ctx))
  41. assert.Equal(s.T(), imageTypePNG, getProcessingOptions(ctx).Format)
  42. }
  43. func (s *ProcessingOptionsTestSuite) TestParseBase64URLInvalid() {
  44. imageURL := "lorem/ipsum.jpg?param=value"
  45. req := s.getRequest(fmt.Sprintf("http://example.com/unsafe/size:100:100/%s.png", base64.RawURLEncoding.EncodeToString([]byte(imageURL))))
  46. _, err := parsePath(context.Background(), req)
  47. assert.Equal(s.T(), errInvalidImageURL, err)
  48. }
  49. func (s *ProcessingOptionsTestSuite) TestParsePlainURL() {
  50. imageURL := "http://images.dev/lorem/ipsum.jpg"
  51. req := s.getRequest(fmt.Sprintf("http://example.com/unsafe/size:100:100/plain/%s@png", imageURL))
  52. ctx, err := parsePath(context.Background(), req)
  53. require.Nil(s.T(), err)
  54. assert.Equal(s.T(), imageURL, getImageURL(ctx))
  55. assert.Equal(s.T(), imageTypePNG, getProcessingOptions(ctx).Format)
  56. }
  57. func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithoutExtension() {
  58. imageURL := "http://images.dev/lorem/ipsum.jpg"
  59. req := s.getRequest(fmt.Sprintf("http://example.com/unsafe/size:100:100/plain/%s", imageURL))
  60. ctx, err := parsePath(context.Background(), req)
  61. require.Nil(s.T(), err)
  62. assert.Equal(s.T(), imageURL, getImageURL(ctx))
  63. assert.Equal(s.T(), imageTypeJPEG, getProcessingOptions(ctx).Format)
  64. }
  65. func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscaped() {
  66. imageURL := "http://images.dev/lorem/ipsum.jpg?param=value"
  67. req := s.getRequest(fmt.Sprintf("http://example.com/unsafe/size:100:100/plain/%s@png", url.PathEscape(imageURL)))
  68. ctx, err := parsePath(context.Background(), req)
  69. require.Nil(s.T(), err)
  70. assert.Equal(s.T(), imageURL, getImageURL(ctx))
  71. assert.Equal(s.T(), imageTypePNG, getProcessingOptions(ctx).Format)
  72. }
  73. func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithBase() {
  74. conf.BaseURL = "http://images.dev/"
  75. imageURL := "lorem/ipsum.jpg"
  76. req := s.getRequest(fmt.Sprintf("http://example.com/unsafe/size:100:100/plain/%s@png", imageURL))
  77. ctx, err := parsePath(context.Background(), req)
  78. require.Nil(s.T(), err)
  79. assert.Equal(s.T(), fmt.Sprintf("%s%s", conf.BaseURL, imageURL), getImageURL(ctx))
  80. assert.Equal(s.T(), imageTypePNG, getProcessingOptions(ctx).Format)
  81. }
  82. func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedWithBase() {
  83. conf.BaseURL = "http://images.dev/"
  84. imageURL := "lorem/ipsum.jpg?param=value"
  85. req := s.getRequest(fmt.Sprintf("http://example.com/unsafe/size:100:100/plain/%s@png", url.PathEscape(imageURL)))
  86. ctx, err := parsePath(context.Background(), req)
  87. require.Nil(s.T(), err)
  88. assert.Equal(s.T(), fmt.Sprintf("%s%s", conf.BaseURL, imageURL), getImageURL(ctx))
  89. assert.Equal(s.T(), imageTypePNG, getProcessingOptions(ctx).Format)
  90. }
  91. func (s *ProcessingOptionsTestSuite) TestParsePlainURLInvalid() {
  92. imageURL := "lorem/ipsum.jpg?param=value"
  93. req := s.getRequest(fmt.Sprintf("http://example.com/unsafe/size:100:100/plain/%s@png", imageURL))
  94. _, err := parsePath(context.Background(), req)
  95. assert.Equal(s.T(), errInvalidImageURL, err)
  96. }
  97. func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscapedInvalid() {
  98. imageURL := "lorem/ipsum.jpg?param=value"
  99. req := s.getRequest(fmt.Sprintf("http://example.com/unsafe/size:100:100/plain/%s@png", url.PathEscape(imageURL)))
  100. _, err := parsePath(context.Background(), req)
  101. assert.Equal(s.T(), errInvalidImageURL, err)
  102. }
  103. func (s *ProcessingOptionsTestSuite) TestParsePathBasic() {
  104. req := s.getRequest("http://example.com/unsafe/fill/100/200/noea/1/plain/http://images.dev/lorem/ipsum.jpg@png")
  105. ctx, err := parsePath(context.Background(), req)
  106. require.Nil(s.T(), err)
  107. po := getProcessingOptions(ctx)
  108. assert.Equal(s.T(), resizeFill, po.Resize)
  109. assert.Equal(s.T(), 100, po.Width)
  110. assert.Equal(s.T(), 200, po.Height)
  111. assert.Equal(s.T(), gravityNorthEast, po.Gravity.Type)
  112. assert.True(s.T(), po.Enlarge)
  113. assert.Equal(s.T(), imageTypePNG, po.Format)
  114. }
  115. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedFormat() {
  116. req := s.getRequest("http://example.com/unsafe/format:webp/plain/http://images.dev/lorem/ipsum.jpg")
  117. ctx, err := parsePath(context.Background(), req)
  118. require.Nil(s.T(), err)
  119. po := getProcessingOptions(ctx)
  120. assert.Equal(s.T(), imageTypeWEBP, po.Format)
  121. }
  122. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedResize() {
  123. req := s.getRequest("http://example.com/unsafe/resize:fill:100:200:1/plain/http://images.dev/lorem/ipsum.jpg")
  124. ctx, err := parsePath(context.Background(), req)
  125. require.Nil(s.T(), err)
  126. po := getProcessingOptions(ctx)
  127. assert.Equal(s.T(), resizeFill, po.Resize)
  128. assert.Equal(s.T(), 100, po.Width)
  129. assert.Equal(s.T(), 200, po.Height)
  130. assert.True(s.T(), po.Enlarge)
  131. }
  132. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedResizingType() {
  133. req := s.getRequest("http://example.com/unsafe/resizing_type:fill/plain/http://images.dev/lorem/ipsum.jpg")
  134. ctx, err := parsePath(context.Background(), req)
  135. require.Nil(s.T(), err)
  136. po := getProcessingOptions(ctx)
  137. assert.Equal(s.T(), resizeFill, po.Resize)
  138. }
  139. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedSize() {
  140. req := s.getRequest("http://example.com/unsafe/size:100:200:1/plain/http://images.dev/lorem/ipsum.jpg")
  141. ctx, err := parsePath(context.Background(), req)
  142. require.Nil(s.T(), err)
  143. po := getProcessingOptions(ctx)
  144. assert.Equal(s.T(), 100, po.Width)
  145. assert.Equal(s.T(), 200, po.Height)
  146. assert.True(s.T(), po.Enlarge)
  147. }
  148. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedWidth() {
  149. req := s.getRequest("http://example.com/unsafe/width:100/plain/http://images.dev/lorem/ipsum.jpg")
  150. ctx, err := parsePath(context.Background(), req)
  151. require.Nil(s.T(), err)
  152. po := getProcessingOptions(ctx)
  153. assert.Equal(s.T(), 100, po.Width)
  154. }
  155. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedHeight() {
  156. req := s.getRequest("http://example.com/unsafe/height:100/plain/http://images.dev/lorem/ipsum.jpg")
  157. ctx, err := parsePath(context.Background(), req)
  158. require.Nil(s.T(), err)
  159. po := getProcessingOptions(ctx)
  160. assert.Equal(s.T(), 100, po.Height)
  161. }
  162. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedEnlarge() {
  163. req := s.getRequest("http://example.com/unsafe/enlarge:1/plain/http://images.dev/lorem/ipsum.jpg")
  164. ctx, err := parsePath(context.Background(), req)
  165. require.Nil(s.T(), err)
  166. po := getProcessingOptions(ctx)
  167. assert.True(s.T(), po.Enlarge)
  168. }
  169. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedGravity() {
  170. req := s.getRequest("http://example.com/unsafe/gravity:soea/plain/http://images.dev/lorem/ipsum.jpg")
  171. ctx, err := parsePath(context.Background(), req)
  172. require.Nil(s.T(), err)
  173. po := getProcessingOptions(ctx)
  174. assert.Equal(s.T(), gravitySouthEast, po.Gravity.Type)
  175. }
  176. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedGravityFocuspoint() {
  177. req := s.getRequest("http://example.com/unsafe/gravity:fp:0.5:0.75/plain/http://images.dev/lorem/ipsum.jpg")
  178. ctx, err := parsePath(context.Background(), req)
  179. require.Nil(s.T(), err)
  180. po := getProcessingOptions(ctx)
  181. assert.Equal(s.T(), gravityFocusPoint, po.Gravity.Type)
  182. assert.Equal(s.T(), 0.5, po.Gravity.X)
  183. assert.Equal(s.T(), 0.75, po.Gravity.Y)
  184. }
  185. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedQuality() {
  186. req := s.getRequest("http://example.com/unsafe/quality:55/plain/http://images.dev/lorem/ipsum.jpg")
  187. ctx, err := parsePath(context.Background(), req)
  188. require.Nil(s.T(), err)
  189. po := getProcessingOptions(ctx)
  190. assert.Equal(s.T(), 55, po.Quality)
  191. }
  192. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedBackground() {
  193. req := s.getRequest("http://example.com/unsafe/background:128:129:130/plain/http://images.dev/lorem/ipsum.jpg")
  194. ctx, err := parsePath(context.Background(), req)
  195. require.Nil(s.T(), err)
  196. po := getProcessingOptions(ctx)
  197. assert.True(s.T(), po.Flatten)
  198. assert.Equal(s.T(), uint8(128), po.Background.R)
  199. assert.Equal(s.T(), uint8(129), po.Background.G)
  200. assert.Equal(s.T(), uint8(130), po.Background.B)
  201. }
  202. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedBackgroundHex() {
  203. req := s.getRequest("http://example.com/unsafe/background:ffddee/plain/http://images.dev/lorem/ipsum.jpg")
  204. ctx, err := parsePath(context.Background(), req)
  205. require.Nil(s.T(), err)
  206. po := getProcessingOptions(ctx)
  207. assert.True(s.T(), po.Flatten)
  208. assert.Equal(s.T(), uint8(0xff), po.Background.R)
  209. assert.Equal(s.T(), uint8(0xdd), po.Background.G)
  210. assert.Equal(s.T(), uint8(0xee), po.Background.B)
  211. }
  212. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedBackgroundDisable() {
  213. req := s.getRequest("http://example.com/unsafe/background:fff/background:/plain/http://images.dev/lorem/ipsum.jpg")
  214. ctx, err := parsePath(context.Background(), req)
  215. require.Nil(s.T(), err)
  216. po := getProcessingOptions(ctx)
  217. assert.False(s.T(), po.Flatten)
  218. }
  219. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedBlur() {
  220. req := s.getRequest("http://example.com/unsafe/blur:0.2/plain/http://images.dev/lorem/ipsum.jpg")
  221. ctx, err := parsePath(context.Background(), req)
  222. require.Nil(s.T(), err)
  223. po := getProcessingOptions(ctx)
  224. assert.Equal(s.T(), float32(0.2), po.Blur)
  225. }
  226. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedSharpen() {
  227. req := s.getRequest("http://example.com/unsafe/sharpen:0.2/plain/http://images.dev/lorem/ipsum.jpg")
  228. ctx, err := parsePath(context.Background(), req)
  229. require.Nil(s.T(), err)
  230. po := getProcessingOptions(ctx)
  231. assert.Equal(s.T(), float32(0.2), po.Sharpen)
  232. }
  233. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedWatermark() {
  234. req := s.getRequest("http://example.com/unsafe/watermark:0.5:soea:10:20:0.6/plain/http://images.dev/lorem/ipsum.jpg")
  235. ctx, err := parsePath(context.Background(), req)
  236. require.Nil(s.T(), err)
  237. po := getProcessingOptions(ctx)
  238. assert.True(s.T(), po.Watermark.Enabled)
  239. assert.Equal(s.T(), gravitySouthEast, po.Watermark.Gravity)
  240. assert.Equal(s.T(), 10, po.Watermark.OffsetX)
  241. assert.Equal(s.T(), 20, po.Watermark.OffsetY)
  242. assert.Equal(s.T(), 0.6, po.Watermark.Scale)
  243. }
  244. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedPreset() {
  245. conf.Presets["test1"] = urlOptions{
  246. "resizing_type": []string{"fill"},
  247. }
  248. conf.Presets["test2"] = urlOptions{
  249. "blur": []string{"0.2"},
  250. "quality": []string{"50"},
  251. }
  252. req := s.getRequest("http://example.com/unsafe/preset:test1:test2/plain/http://images.dev/lorem/ipsum.jpg")
  253. ctx, err := parsePath(context.Background(), req)
  254. require.Nil(s.T(), err)
  255. po := getProcessingOptions(ctx)
  256. assert.Equal(s.T(), resizeFill, po.Resize)
  257. assert.Equal(s.T(), float32(0.2), po.Blur)
  258. assert.Equal(s.T(), 50, po.Quality)
  259. }
  260. func (s *ProcessingOptionsTestSuite) TestParsePathPresetDefault() {
  261. conf.Presets["default"] = urlOptions{
  262. "resizing_type": []string{"fill"},
  263. "blur": []string{"0.2"},
  264. "quality": []string{"50"},
  265. }
  266. req := s.getRequest("http://example.com/unsafe/quality:70/plain/http://images.dev/lorem/ipsum.jpg")
  267. ctx, err := parsePath(context.Background(), req)
  268. require.Nil(s.T(), err)
  269. po := getProcessingOptions(ctx)
  270. assert.Equal(s.T(), resizeFill, po.Resize)
  271. assert.Equal(s.T(), float32(0.2), po.Blur)
  272. assert.Equal(s.T(), 70, po.Quality)
  273. }
  274. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedPresetLoopDetection() {
  275. conf.Presets["test1"] = urlOptions{
  276. "resizing_type": []string{"fill"},
  277. }
  278. conf.Presets["test2"] = urlOptions{
  279. "blur": []string{"0.2"},
  280. "quality": []string{"50"},
  281. }
  282. req := s.getRequest("http://example.com/unsafe/preset:test1:test2:test1/plain/http://images.dev/lorem/ipsum.jpg")
  283. _, err := parsePath(context.Background(), req)
  284. require.Error(s.T(), err)
  285. }
  286. func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedCachebuster() {
  287. req := s.getRequest("http://example.com/unsafe/cachebuster:123/plain/http://images.dev/lorem/ipsum.jpg")
  288. ctx, err := parsePath(context.Background(), req)
  289. require.Nil(s.T(), err)
  290. po := getProcessingOptions(ctx)
  291. assert.Equal(s.T(), "123", po.CacheBuster)
  292. }
  293. func (s *ProcessingOptionsTestSuite) TestParsePathWebpDetection() {
  294. conf.EnableWebpDetection = true
  295. req := s.getRequest("http://example.com/unsafe/plain/http://images.dev/lorem/ipsum.jpg")
  296. req.Header.Set("Accept", "image/webp")
  297. ctx, err := parsePath(context.Background(), req)
  298. require.Nil(s.T(), err)
  299. po := getProcessingOptions(ctx)
  300. assert.Equal(s.T(), imageTypeWEBP, po.Format)
  301. }
  302. func (s *ProcessingOptionsTestSuite) TestParsePathWebpDetectionRedefine() {
  303. conf.EnableWebpDetection = true
  304. req := s.getRequest("http://example.com/unsafe/plain/http://images.dev/lorem/ipsum.jpg@png")
  305. req.Header.Set("Accept", "image/webp")
  306. ctx, err := parsePath(context.Background(), req)
  307. require.Nil(s.T(), err)
  308. po := getProcessingOptions(ctx)
  309. assert.Equal(s.T(), imageTypePNG, po.Format)
  310. }
  311. func (s *ProcessingOptionsTestSuite) TestParsePathWebpEnforce() {
  312. conf.EnforceWebp = true
  313. req := s.getRequest("http://example.com/unsafe/plain/http://images.dev/lorem/ipsum.jpg@png")
  314. req.Header.Set("Accept", "image/webp")
  315. ctx, err := parsePath(context.Background(), req)
  316. require.Nil(s.T(), err)
  317. po := getProcessingOptions(ctx)
  318. assert.Equal(s.T(), imageTypeWEBP, po.Format)
  319. }
  320. func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeader() {
  321. conf.EnableClientHints = true
  322. req := s.getRequest("http://example.com/unsafe/plain/http://images.dev/lorem/ipsum.jpg@png")
  323. req.Header.Set("Width", "100")
  324. ctx, err := parsePath(context.Background(), req)
  325. require.Nil(s.T(), err)
  326. po := getProcessingOptions(ctx)
  327. assert.Equal(s.T(), 100, po.Width)
  328. }
  329. func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderDisabled() {
  330. req := s.getRequest("http://example.com/unsafe/plain/http://images.dev/lorem/ipsum.jpg@png")
  331. req.Header.Set("Width", "100")
  332. ctx, err := parsePath(context.Background(), req)
  333. require.Nil(s.T(), err)
  334. po := getProcessingOptions(ctx)
  335. assert.Equal(s.T(), 0, po.Width)
  336. }
  337. func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderRedefine() {
  338. conf.EnableClientHints = true
  339. req := s.getRequest("http://example.com/unsafe/width:150/plain/http://images.dev/lorem/ipsum.jpg@png")
  340. req.Header.Set("Width", "100")
  341. ctx, err := parsePath(context.Background(), req)
  342. require.Nil(s.T(), err)
  343. po := getProcessingOptions(ctx)
  344. assert.Equal(s.T(), 150, po.Width)
  345. }
  346. func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeader() {
  347. conf.EnableClientHints = true
  348. req := s.getRequest("http://example.com/unsafe/plain/http://images.dev/lorem/ipsum.jpg@png")
  349. req.Header.Set("Viewport-Width", "100")
  350. ctx, err := parsePath(context.Background(), req)
  351. require.Nil(s.T(), err)
  352. po := getProcessingOptions(ctx)
  353. assert.Equal(s.T(), 100, po.Width)
  354. }
  355. func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeaderDisabled() {
  356. req := s.getRequest("http://example.com/unsafe/plain/http://images.dev/lorem/ipsum.jpg@png")
  357. req.Header.Set("Viewport-Width", "100")
  358. ctx, err := parsePath(context.Background(), req)
  359. require.Nil(s.T(), err)
  360. po := getProcessingOptions(ctx)
  361. assert.Equal(s.T(), 0, po.Width)
  362. }
  363. func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeaderRedefine() {
  364. conf.EnableClientHints = true
  365. req := s.getRequest("http://example.com/unsafe/width:150/plain/http://images.dev/lorem/ipsum.jpg@png")
  366. req.Header.Set("Viewport-Width", "100")
  367. ctx, err := parsePath(context.Background(), req)
  368. require.Nil(s.T(), err)
  369. po := getProcessingOptions(ctx)
  370. assert.Equal(s.T(), 150, po.Width)
  371. }
  372. func (s *ProcessingOptionsTestSuite) TestParsePathSigned() {
  373. conf.Key = []byte("test-key")
  374. conf.Salt = []byte("test-salt")
  375. conf.AllowInsecure = false
  376. req := s.getRequest("http://example.com/HcvNognEV1bW6f8zRqxNYuOkV0IUf1xloRb57CzbT4g/width:150/plain/http://images.dev/lorem/ipsum.jpg@png")
  377. _, err := parsePath(context.Background(), req)
  378. require.Nil(s.T(), err)
  379. }
  380. func (s *ProcessingOptionsTestSuite) TestParsePathSignedInvalid() {
  381. conf.Key = []byte("test-key")
  382. conf.Salt = []byte("test-salt")
  383. conf.AllowInsecure = false
  384. req := s.getRequest("http://example.com/unsafe/width:150/plain/http://images.dev/lorem/ipsum.jpg@png")
  385. _, err := parsePath(context.Background(), req)
  386. require.Equal(s.T(), errInvalidToken, err)
  387. }
  388. func TestProcessingOptions(t *testing.T) {
  389. suite.Run(t, new(ProcessingOptionsTestSuite))
  390. }