|
| 1 | +// Copyright 2022 The Gitea Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package markup |
| 6 | + |
| 7 | +import ( |
| 8 | + "testing" |
| 9 | + |
| 10 | + "code.gitea.io/gitea/modules/setting" |
| 11 | + |
| 12 | + "github.com/stretchr/testify/assert" |
| 13 | +) |
| 14 | + |
| 15 | +func TestCamoHandleLink(t *testing.T) { |
| 16 | + setting.AppURL = "https://gitea.com" |
| 17 | + // Test media proxy |
| 18 | + setting.Camo.Enabled = true |
| 19 | + setting.Camo.ServerURL = "https://image.proxy" |
| 20 | + setting.Camo.HMACKey = "geheim" |
| 21 | + |
| 22 | + assert.Equal(t, |
| 23 | + "https://gitea.com/img.jpg", |
| 24 | + camoHandleLink("https://gitea.com/img.jpg")) |
| 25 | + assert.Equal(t, |
| 26 | + "https://testimages.org/img.jpg", |
| 27 | + camoHandleLink("https://testimages.org/img.jpg")) |
| 28 | + assert.Equal(t, |
| 29 | + "https://image.proxy/eivin43gJwGVIjR9MiYYtFIk0mw/aHR0cDovL3Rlc3RpbWFnZXMub3JnL2ltZy5qcGc", |
| 30 | + camoHandleLink("http://testimages.org/img.jpg")) |
| 31 | + |
| 32 | + setting.Camo.Allways = true |
| 33 | + assert.Equal(t, |
| 34 | + "https://gitea.com/img.jpg", |
| 35 | + camoHandleLink("https://gitea.com/img.jpg")) |
| 36 | + assert.Equal(t, |
| 37 | + "https://image.proxy/tkdlvmqpbIr7SjONfHNgEU622y0/aHR0cHM6Ly90ZXN0aW1hZ2VzLm9yZy9pbWcuanBn", |
| 38 | + camoHandleLink("https://testimages.org/img.jpg")) |
| 39 | + assert.Equal(t, |
| 40 | + "https://image.proxy/eivin43gJwGVIjR9MiYYtFIk0mw/aHR0cDovL3Rlc3RpbWFnZXMub3JnL2ltZy5qcGc", |
| 41 | + camoHandleLink("http://testimages.org/img.jpg")) |
| 42 | + |
| 43 | + // Restore previous settings |
| 44 | + setting.Camo.Enabled = false |
| 45 | +} |
0 commit comments