commit
c8f78e8469
|
|
@ -24,10 +24,11 @@ jobs:
|
||||||
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
|
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
|
||||||
restore-keys: ${{ runner.os }}-node_modules-
|
restore-keys: ${{ runner.os }}-node_modules-
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: golangci/golangci-lint-action@v2
|
- uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
version: v1.45
|
version: v1.45
|
||||||
args: --timeout=5m
|
args: --timeout=5m
|
||||||
|
skip-cache: true
|
||||||
- run: go mod download
|
- run: go mod download
|
||||||
- run: make download-tools
|
- run: make download-tools
|
||||||
- run: (cd ui && yarn)
|
- run: (cd ui && yarn)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gotify/server/v2/config"
|
"github.com/gotify/server/v2/config"
|
||||||
|
|
@ -75,7 +76,11 @@ func redirectToHTTPS(port string) http.HandlerFunc {
|
||||||
func changePort(hostPort, port string) string {
|
func changePort(hostPort, port string) string {
|
||||||
host, _, err := net.SplitHostPort(hostPort)
|
host, _, err := net.SplitHostPort(hostPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// There is no exported error.
|
||||||
|
if !strings.Contains(err.Error(), "missing port") {
|
||||||
return hostPort
|
return hostPort
|
||||||
}
|
}
|
||||||
|
host = hostPort
|
||||||
|
}
|
||||||
return net.JoinHostPort(host, port)
|
return net.JoinHostPort(host, port)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package runner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRedirect(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Request string
|
||||||
|
TLS int
|
||||||
|
Expect string
|
||||||
|
}{
|
||||||
|
{Request: "http://gotify.net/meow", TLS: 443, Expect: "https://gotify.net:443/meow"},
|
||||||
|
{Request: "http://gotify.net:8080/meow", TLS: 443, Expect: "https://gotify.net:443/meow"},
|
||||||
|
{Request: "http://gotify.net:8080/meow", TLS: 8443, Expect: "https://gotify.net:8443/meow"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range cases {
|
||||||
|
name := fmt.Sprintf("%s -- %d -> %s", testCase.Request, testCase.TLS, testCase.Expect)
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
req := httptest.NewRequest("GET", testCase.Request, nil)
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
|
||||||
|
redirectToHTTPS(fmt.Sprint(testCase.TLS)).ServeHTTP(rec, req)
|
||||||
|
|
||||||
|
assert.Equal(t, http.StatusFound, rec.Result().StatusCode)
|
||||||
|
assert.Equal(t, testCase.Expect, rec.Header().Get("location"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue