Fix alias generation (#294)

* added test
* fix missing domain
This commit is contained in:
Benjamin Steinwender 2022-01-18 09:31:01 +01:00 committed by GitHub
parent e3cea25e25
commit 6f5edbaa43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View File

@ -55,6 +55,7 @@ func (sed ServerEndpointDetails) URLForAlias(a string) string {
if sed.UseSubdomainForAliases {
u.Host = a + "." + sed.Domain
} else {
u.Host = sed.Domain
u.Path = "/alias/" + a
}

View File

@ -8,6 +8,7 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"net/url"
"testing"
@ -15,6 +16,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/ssb-ngi-pointer/go-ssb-room/v2/internal/network"
"github.com/ssb-ngi-pointer/go-ssb-room/v2/internal/randutil"
"github.com/ssb-ngi-pointer/go-ssb-room/v2/roomdb"
"github.com/ssb-ngi-pointer/go-ssb-room/v2/web/router"
refs "go.mindeco.de/ssb-refs"
@ -160,3 +163,27 @@ func TestAliasResolveOnAndroidChrome(t *testing.T) {
frag := aliasURI.Fragment
a.Equal("Intent;scheme=ssb;end;", frag)
}
func TestURLForAlias(t *testing.T) {
ts := setup(t)
a := assert.New(t)
ts.netInfo = network.ServerEndpointDetails{
Domain: randutil.String(10),
UseSubdomainForAliases: true,
}
// test subdomain alias URLs
generatedURL := ts.netInfo.URLForAlias("dummy")
expectedURL := fmt.Sprintf("https://dummy.%s", ts.netInfo.Domain)
a.Equal(expectedURL, generatedURL)
// test alias URLs using /alias/-path
ts.netInfo.UseSubdomainForAliases = false
generatedURL = ts.netInfo.URLForAlias("dummy")
expectedURL = fmt.Sprintf("https://%s/alias/dummy", ts.netInfo.Domain)
a.Equal(expectedURL, generatedURL)
}

View File

@ -33,6 +33,8 @@ type testSession struct {
Client *tester.Tester
URLTo web.URLMaker
netInfo network.ServerEndpointDetails
// mocked dbs
AuthDB *mockdb.FakeAuthWithSSBService
AuthFallbackDB *mockdb.FakeAuthFallbackService