github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/markup/camo_test.go (about)

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