summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-11-24 15:40:39 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-11-24 15:40:39 +0100
commit8be555e5f91c6069c3d51cb014f1849fd182b1dc (patch)
tree9c78f2ee1f5122da1e1ed3e452682f7f6744778f /internal
parent791fffebff4499e4fad3217e2160596e1b8b3eea (diff)
Style: Use stylecheck and fix errors
Diffstat (limited to 'internal')
-rw-r--r--internal/discovery/discovery.go6
-rw-r--r--internal/fsm/fsm.go14
-rw-r--r--internal/http/http.go4
-rw-r--r--internal/log/log.go48
-rw-r--r--internal/oauth/oauth.go24
-rw-r--r--internal/server/api.go12
-rw-r--r--internal/server/common.go13
-rw-r--r--internal/server/custom.go6
-rw-r--r--internal/server/instituteaccess.go6
-rw-r--r--internal/server/secureinternet.go40
-rw-r--r--internal/util/util_test.go11
-rw-r--r--internal/verify/verify.go12
-rw-r--r--internal/wireguard/wireguard.go10
13 files changed, 102 insertions, 104 deletions
diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go
index 01978fe..b0b20fa 100644
--- a/internal/discovery/discovery.go
+++ b/internal/discovery/discovery.go
@@ -113,7 +113,7 @@ func (discovery *Discovery) GetServerByCountryCode(
func (discovery *Discovery) getOrgByID(orgID string) (*types.DiscoveryOrganization, error) {
for _, organization := range discovery.Organizations.List {
- if organization.OrgId == orgID {
+ if organization.OrgID == orgID {
return &organization, nil
}
}
@@ -153,9 +153,9 @@ func (discovery *Discovery) DetermineServersUpdate() bool {
return true
}
// 1 hour from the last update
- should_update_time := discovery.Servers.Timestamp.Add(1 * time.Hour)
+ shouldUpdateTime := discovery.Servers.Timestamp.Add(1 * time.Hour)
now := time.Now()
- return !now.Before(should_update_time)
+ return !now.Before(shouldUpdateTime)
}
// Get the organization list
diff --git a/internal/fsm/fsm.go b/internal/fsm/fsm.go
index 1b45ce8..b51a5c9 100644
--- a/internal/fsm/fsm.go
+++ b/internal/fsm/fsm.go
@@ -75,8 +75,8 @@ func (fsm *FSM) InState(check FSMStateID) bool {
}
func (fsm *FSM) HasTransition(check FSMStateID) bool {
- for _, transition_state := range fsm.States[fsm.Current].Transitions {
- if transition_state.To == check {
+ for _, transitionState := range fsm.States[fsm.Current].Transitions {
+ if transitionState.To == check {
return true
}
}
@@ -143,12 +143,12 @@ func (fsm *FSM) GoTransition(newState FSMStateID) bool {
func (fsm *FSM) generateMermaidGraph() string {
graph := "graph TD\n"
- sorted_fsm := make(FSMStateIDSlice, 0, len(fsm.States))
- for state_id := range fsm.States {
- sorted_fsm = append(sorted_fsm, state_id)
+ sortedFSM := make(FSMStateIDSlice, 0, len(fsm.States))
+ for stateID := range fsm.States {
+ sortedFSM = append(sortedFSM, stateID)
}
- sort.Sort(sorted_fsm)
- for _, state := range sorted_fsm {
+ sort.Sort(sortedFSM)
+ for _, state := range sortedFSM {
transitions := fsm.States[state].Transitions
for _, transition := range transitions {
if state == fsm.Current {
diff --git a/internal/http/http.go b/internal/http/http.go
index 005a665..a9d3ea2 100644
--- a/internal/http/http.go
+++ b/internal/http/http.go
@@ -170,13 +170,13 @@ func (e *HTTPStatusError) Error() string {
)
}
-type HTTPParseJsonError struct {
+type HTTPParseJSONError struct {
URL string
Body string
Err error
}
-func (e *HTTPParseJsonError) Error() string {
+func (e *HTTPParseJSONError) Error() string {
return fmt.Sprintf(
"failed parsing json %s for HTTP resource: %s with error: %v",
e.Body,
diff --git a/internal/log/log.go b/internal/log/log.go
index 8dc3ad0..2ab6549 100644
--- a/internal/log/log.go
+++ b/internal/log/log.go
@@ -20,32 +20,32 @@ type LogLevel int8
const (
// No level set, not allowed
- LOG_NOTSET LogLevel = iota
+ LogNotSet LogLevel = iota
// Log debug, this message is not an error but is there for debugging
- LOG_DEBUG
+ LogDebug
// Log info, this message is not an error but is there for additional information
- LOG_INFO
+ LogInfo
// Log only to provide a warning, the app still functions
- LOG_WARNING
+ LogWarning
// Log to provide a generic error, the app still functions but some functionality might not work
- LOG_ERROR
+ LogError
// Log to provide a fatal error, the app cannot function correctly when such an error occurs
- LOG_FATAL
+ LogFatal
)
func (e LogLevel) String() string {
switch e {
- case LOG_NOTSET:
+ case LogNotSet:
return "NOTSET"
- case LOG_DEBUG:
+ case LogDebug:
return "DEBUG"
- case LOG_INFO:
+ case LogInfo:
return "INFO"
- case LOG_WARNING:
+ case LogWarning:
return "WARNING"
- case LOG_ERROR:
+ case LogError:
return "ERROR"
- case LOG_FATAL:
+ case LogFatal:
return "FATAL"
default:
return "UNKNOWN"
@@ -79,35 +79,35 @@ func (logger *FileLogger) Inherit(label string, err error) {
msg := fmt.Sprintf("%s with err: %s", label, types.GetErrorTraceback(err))
switch level {
- case types.ERR_INFO:
+ case types.ErrInfo:
logger.Info(msg)
- case types.ERR_WARNING:
+ case types.ErrWarning:
logger.Warning(msg)
- case types.ERR_OTHER:
+ case types.ErrOther:
logger.Error(msg)
- case types.ERR_FATAL:
+ case types.ErrFatal:
logger.Fatal(msg)
}
}
func (logger *FileLogger) Debug(msg string, params ...interface{}) {
- logger.log(LOG_DEBUG, msg, params...)
+ logger.log(LogDebug, msg, params...)
}
func (logger *FileLogger) Info(msg string, params ...interface{}) {
- logger.log(LOG_INFO, msg, params...)
+ logger.log(LogInfo, msg, params...)
}
func (logger *FileLogger) Warning(msg string, params ...interface{}) {
- logger.log(LOG_WARNING, msg, params...)
+ logger.log(LogWarning, msg, params...)
}
func (logger *FileLogger) Error(msg string, params ...interface{}) {
- logger.log(LOG_ERROR, msg, params...)
+ logger.log(LogError, msg, params...)
}
func (logger *FileLogger) Fatal(msg string, params ...interface{}) {
- logger.log(LOG_FATAL, msg, params...)
+ logger.log(LogFatal, msg, params...)
}
func (logger *FileLogger) Close() {
@@ -119,9 +119,9 @@ func (logger *FileLogger) getFilename(directory string) string {
}
func (logger *FileLogger) log(level LogLevel, msg string, params ...interface{}) {
- if level >= logger.Level && logger.Level != LOG_NOTSET {
- formatted_msg := fmt.Sprintf(msg, params...)
- format := fmt.Sprintf("- Go - %s - %s", level.String(), formatted_msg)
+ if level >= logger.Level && logger.Level != LogNotSet {
+ formattedMsg := fmt.Sprintf(msg, params...)
+ format := fmt.Sprintf("- Go - %s - %s", level.String(), formattedMsg)
// To log file
log.Println(format)
}
diff --git a/internal/oauth/oauth.go b/internal/oauth/oauth.go
index 9518d79..1f3b719 100644
--- a/internal/oauth/oauth.go
+++ b/internal/oauth/oauth.go
@@ -121,7 +121,7 @@ func (oauth *OAuth) setupListener() error {
func (oauth *OAuth) getTokensWithCallback() error {
errorMessage := "failed getting tokens with callback"
if oauth.Session.Listener == nil {
- return types.NewWrappedError(errorMessage, errors.New("No listener"))
+ return types.NewWrappedError(errorMessage, errors.New("no listener"))
}
mux := http.NewServeMux()
// server /callback over the listener address
@@ -161,7 +161,7 @@ func (oauth *OAuth) getTokensWithAuthCode(authCode string) error {
"content-type": {"application/x-www-form-urlencoded"},
}
opts := &httpw.HTTPOptionalParams{Headers: headers, Body: data}
- current_time := time.Now()
+ currentTime := time.Now()
_, body, bodyErr := httpw.HTTPPostWithOpts(reqURL, opts)
if bodyErr != nil {
return types.NewWrappedError(errorMessage, bodyErr)
@@ -174,11 +174,11 @@ func (oauth *OAuth) getTokensWithAuthCode(authCode string) error {
if jsonErr != nil {
return types.NewWrappedError(
errorMessage,
- &httpw.HTTPParseJsonError{URL: reqURL, Body: string(body), Err: jsonErr},
+ &httpw.HTTPParseJSONError{URL: reqURL, Body: string(body), Err: jsonErr},
)
}
- tokenStructure.ExpiredTimestamp = current_time.Add(
+ tokenStructure.ExpiredTimestamp = currentTime.Add(
time.Second * time.Duration(tokenStructure.Expires),
)
oauth.Token = tokenStructure
@@ -186,9 +186,9 @@ func (oauth *OAuth) getTokensWithAuthCode(authCode string) error {
}
func (oauth *OAuth) isTokensExpired() bool {
- expired_time := oauth.Token.ExpiredTimestamp
- current_time := time.Now()
- return !current_time.Before(expired_time)
+ expiredTime := oauth.Token.ExpiredTimestamp
+ currentTime := time.Now()
+ return !currentTime.Before(expiredTime)
}
// Get the access and refresh tokens with a previously received refresh token
@@ -205,7 +205,7 @@ func (oauth *OAuth) getTokensWithRefresh() error {
"content-type": {"application/x-www-form-urlencoded"},
}
opts := &httpw.HTTPOptionalParams{Headers: headers, Body: data}
- current_time := time.Now()
+ currentTime := time.Now()
_, body, bodyErr := httpw.HTTPPostWithOpts(reqURL, opts)
if bodyErr != nil {
return types.NewWrappedError(errorMessage, bodyErr)
@@ -217,11 +217,11 @@ func (oauth *OAuth) getTokensWithRefresh() error {
if jsonErr != nil {
return types.NewWrappedError(
errorMessage,
- &httpw.HTTPParseJsonError{URL: reqURL, Body: string(body), Err: jsonErr},
+ &httpw.HTTPParseJSONError{URL: reqURL, Body: string(body), Err: jsonErr},
)
}
- tokenStructure.ExpiredTimestamp = current_time.Add(
+ tokenStructure.ExpiredTimestamp = currentTime.Add(
time.Second * time.Duration(tokenStructure.Expires),
)
oauth.Token = tokenStructure
@@ -374,7 +374,7 @@ func (oauth OAuth) GetListenerPort() (int, error) {
errorMessage := "failed to get listener port"
if oauth.Session.Listener == nil {
- return 0, types.NewWrappedError(errorMessage, errors.New("No OAuth listener"))
+ return 0, types.NewWrappedError(errorMessage, errors.New("no OAuth listener"))
}
return oauth.Session.Listener.Addr().(*net.TCPAddr).Port, nil
}
@@ -444,7 +444,7 @@ func (oauth *OAuth) Exchange() error {
func (oauth *OAuth) Cancel() {
oauth.Session.CallbackError = types.NewWrappedErrorLevel(
- types.ERR_INFO,
+ types.ErrInfo,
"cancelled OAuth",
&OAuthCancelledCallbackError{},
)
diff --git a/internal/server/api.go b/internal/server/api.go
index be7281c..d315ada 100644
--- a/internal/server/api.go
+++ b/internal/server/api.go
@@ -20,7 +20,9 @@ func APIGetEndpoints(baseURL string) (*ServerEndpoints, error) {
return nil, types.NewWrappedError(errorMessage, urlErr)
}
- url.Path = path.Join(url.Path, WellKnownPath)
+ wellKnownPath := "/.well-known/vpn-user-portal"
+
+ url.Path = path.Join(url.Path, wellKnownPath)
_, body, bodyErr := httpw.HTTPGet(url.String())
if bodyErr != nil {
@@ -140,7 +142,7 @@ func GetPreferTCPString(preferTCP bool) string {
func APIConnectWireguard(
server Server,
- profile_id string,
+ profileID string,
pubkey string,
preferTCP bool,
supportsOpenVPN bool,
@@ -158,7 +160,7 @@ func APIConnectWireguard(
}
urlForm := url.Values{
- "profile_id": {profile_id},
+ "profile_id": {profileID},
"public_key": {pubkey},
"prefer_tcp": {GetPreferTCPString(preferTCP)},
}
@@ -191,7 +193,7 @@ func APIConnectWireguard(
return string(connectBody), content, pTime, nil
}
-func APIConnectOpenVPN(server Server, profile_id string, preferTCP bool) (string, time.Time, error) {
+func APIConnectOpenVPN(server Server, profileID string, preferTCP bool) (string, time.Time, error) {
errorMessage := "failed obtaining an OpenVPN configuration"
headers := http.Header{
"content-type": {"application/x-www-form-urlencoded"},
@@ -199,7 +201,7 @@ func APIConnectOpenVPN(server Server, profile_id string, preferTCP bool) (string
}
urlForm := url.Values{
- "profile_id": {profile_id},
+ "profile_id": {profileID},
"prefer_tcp": {GetPreferTCPString(preferTCP)},
}
diff --git a/internal/server/common.go b/internal/server/common.go
index 6cd5dc2..8f4eabc 100644
--- a/internal/server/common.go
+++ b/internal/server/common.go
@@ -92,9 +92,6 @@ type ServerEndpoints struct {
V string `json:"v"`
}
-// Make this a var which we can overwrite in the tests
-var WellKnownPath string = "/.well-known/vpn-user-portal"
-
func (servers *Servers) GetCurrentServer() (Server, error) {
errorMessage := "failed getting current server"
if servers.IsType == SecureInternetServerType {
@@ -372,7 +369,7 @@ func wireguardGetConfig(server Server, preferTCP bool, supportsOpenVPN bool) (st
return "", "", types.NewWrappedError(errorMessage, baseErr)
}
- profile_id := base.Profiles.Current
+ profileID := base.Profiles.Current
wireguardKey, wireguardErr := wireguard.GenerateKey()
if wireguardErr != nil {
@@ -382,7 +379,7 @@ func wireguardGetConfig(server Server, preferTCP bool, supportsOpenVPN bool) (st
wireguardPublicKey := wireguardKey.PublicKey().String()
config, content, expires, configErr := APIConnectWireguard(
server,
- profile_id,
+ profileID,
wireguardPublicKey,
preferTCP,
supportsOpenVPN,
@@ -414,8 +411,8 @@ func openVPNGetConfig(server Server, preferTCP bool) (string, string, error) {
if baseErr != nil {
return "", "", types.NewWrappedError(errorMessage, baseErr)
}
- profile_id := base.Profiles.Current
- configOpenVPN, expires, configErr := APIConnectOpenVPN(server, profile_id, preferTCP)
+ profileID := base.Profiles.Current
+ configOpenVPN, expires, configErr := APIConnectOpenVPN(server, profileID, preferTCP)
// Store start and end time
base.StartTime = time.Now()
@@ -515,7 +512,7 @@ func GetConfig(server Server, clientSupportsWireguard bool, preferTCP bool) (str
config, configType, configErr = openVPNGetConfig(server, preferTCP)
// The config supports no available protocol because the profile only supports WireGuard but the client doesn't
} else {
- return "", "", types.NewWrappedError(errorMessage, errors.New("No supported protocol found"))
+ return "", "", types.NewWrappedError(errorMessage, errors.New("no supported protocol found"))
}
if configErr != nil {
diff --git a/internal/server/custom.go b/internal/server/custom.go
index 6ba6503..8bde848 100644
--- a/internal/server/custom.go
+++ b/internal/server/custom.go
@@ -15,14 +15,14 @@ func (servers *Servers) SetCustomServer(server Server) error {
}
if base.Type != "custom_server" {
- return types.NewWrappedError(errorMessage, errors.New("Not a custom server"))
+ return types.NewWrappedError(errorMessage, errors.New("not a custom server"))
}
if _, ok := servers.CustomServers.Map[base.URL]; ok {
servers.CustomServers.CurrentURL = base.URL
servers.IsType = CustomServerType
} else {
- return types.NewWrappedError(errorMessage, errors.New("Not a custom server"))
+ return types.NewWrappedError(errorMessage, errors.New("not a custom server"))
}
return nil
}
@@ -31,7 +31,7 @@ func (servers *Servers) GetCustomServer(url string) (*InstituteAccessServer, err
if server, ok := servers.CustomServers.Map[url]; ok {
return server, nil
}
- return nil, types.NewWrappedError("failed to get institute access server", fmt.Errorf("No custom server with URL: %s", url))
+ return nil, types.NewWrappedError("failed to get institute access server", fmt.Errorf("no custom server with URL: %s", url))
}
func (servers *Servers) RemoveCustomServer(url string) {
diff --git a/internal/server/instituteaccess.go b/internal/server/instituteaccess.go
index 045535a..33d8b52 100644
--- a/internal/server/instituteaccess.go
+++ b/internal/server/instituteaccess.go
@@ -30,14 +30,14 @@ func (servers *Servers) SetInstituteAccess(server Server) error {
}
if base.Type != "institute_access" {
- return types.NewWrappedError(errorMessage, errors.New("Not an institute access server"))
+ return types.NewWrappedError(errorMessage, errors.New("not an institute access server"))
}
if _, ok := servers.InstituteServers.Map[base.URL]; ok {
servers.InstituteServers.CurrentURL = base.URL
servers.IsType = InstituteAccessServerType
} else {
- return types.NewWrappedError(errorMessage, errors.New("No such institute access server"))
+ return types.NewWrappedError(errorMessage, errors.New("no such institute access server"))
}
return nil
}
@@ -46,7 +46,7 @@ func (servers *Servers) GetInstituteAccess(url string) (*InstituteAccessServer,
if server, ok := servers.InstituteServers.Map[url]; ok {
return server, nil
}
- return nil, types.NewWrappedError("failed to get institute access server", fmt.Errorf("No institute access server with URL: %s", url))
+ return nil, types.NewWrappedError("failed to get institute access server", fmt.Errorf("no institute access server with URL: %s", url))
}
func (servers *Servers) RemoveInstituteAccess(url string) {
diff --git a/internal/server/secureinternet.go b/internal/server/secureinternet.go
index cfe9ea1..f0b308f 100644
--- a/internal/server/secureinternet.go
+++ b/internal/server/secureinternet.go
@@ -26,7 +26,7 @@ type SecureInternetHomeServer struct {
func (servers *Servers) GetSecureInternetHomeServer() (*SecureInternetHomeServer, error) {
if !servers.HasSecureLocation() {
- return nil, errors.New("No secure internet home server")
+ return nil, errors.New("no secure internet home server")
}
return &servers.SecureInternetHomeServer, nil
}
@@ -39,7 +39,7 @@ func (servers *Servers) SetSecureInternet(server Server) error {
}
if base.Type != "secure_internet" {
- return types.NewWrappedError(errorMessage, errors.New("Not a secure internet server"))
+ return types.NewWrappedError(errorMessage, errors.New("not a secure internet server"))
}
// The location should already be configured
@@ -58,13 +58,13 @@ func (servers *Servers) RemoveSecureInternet() {
}
}
-func (secure *SecureInternetHomeServer) GetOAuth() *oauth.OAuth {
- return &secure.OAuth
+func (server *SecureInternetHomeServer) GetOAuth() *oauth.OAuth {
+ return &server.OAuth
}
-func (secure *SecureInternetHomeServer) GetTemplateAuth() func(string) string {
+func (server *SecureInternetHomeServer) GetTemplateAuth() func(string) string {
return func(authURL string) string {
- return util.ReplaceWAYF(secure.AuthorizationTemplate, authURL, secure.HomeOrganizationID)
+ return util.ReplaceWAYF(server.AuthorizationTemplate, authURL, server.HomeOrganizationID)
}
}
@@ -92,23 +92,23 @@ func (servers *Servers) HasSecureLocation() bool {
return servers.SecureInternetHomeServer.CurrentLocation != ""
}
-func (secure *SecureInternetHomeServer) addLocation(
+func (server *SecureInternetHomeServer) addLocation(
locationServer *types.DiscoveryServer,
) (*ServerBase, error) {
errorMessage := "failed adding a location"
// Initialize the base map if it is non-nil
- if secure.BaseMap == nil {
- secure.BaseMap = make(map[string]*ServerBase)
+ if server.BaseMap == nil {
+ server.BaseMap = make(map[string]*ServerBase)
}
// Add the location to the base map
- base, exists := secure.BaseMap[locationServer.CountryCode]
+ base, exists := server.BaseMap[locationServer.CountryCode]
if !exists || base == nil {
// Create the base to be added to the map
base = &ServerBase{}
base.URL = locationServer.BaseURL
- base.DisplayName = secure.DisplayName
+ base.DisplayName = server.DisplayName
base.SupportContact = locationServer.SupportContact
base.Type = "secure_internet"
endpointsErr := base.InitializeEndpoints()
@@ -118,37 +118,37 @@ func (secure *SecureInternetHomeServer) addLocation(
}
// Ensure it is in the map
- secure.BaseMap[locationServer.CountryCode] = base
+ server.BaseMap[locationServer.CountryCode] = base
return base, nil
}
// Initializes the home server and adds its own location
-func (secure *SecureInternetHomeServer) init(
+func (server *SecureInternetHomeServer) init(
homeOrg *types.DiscoveryOrganization,
homeLocation *types.DiscoveryServer,
) error {
errorMessage := "failed initializing secure internet home server"
- if secure.HomeOrganizationID != homeOrg.OrgId {
+ if server.HomeOrganizationID != homeOrg.OrgID {
// New home organisation, clear everything
- *secure = SecureInternetHomeServer{}
+ *server = SecureInternetHomeServer{}
}
// Make sure to set the organization ID
- secure.HomeOrganizationID = homeOrg.OrgId
- secure.DisplayName = homeOrg.DisplayName
+ server.HomeOrganizationID = homeOrg.OrgID
+ server.DisplayName = homeOrg.DisplayName
// Make sure to set the authorization URL template
- secure.AuthorizationTemplate = homeLocation.AuthenticationURLTemplate
+ server.AuthorizationTemplate = homeLocation.AuthenticationURLTemplate
- base, baseErr := secure.addLocation(homeLocation)
+ base, baseErr := server.addLocation(homeLocation)
if baseErr != nil {
return types.NewWrappedError(errorMessage, baseErr)
}
// Make sure oauth contains our endpoints
- secure.OAuth.Init(base.URL, base.Endpoints.API.V3.Authorization, base.Endpoints.API.V3.Token)
+ server.OAuth.Init(base.URL, base.Endpoints.API.V3.Authorization, base.Endpoints.API.V3.Token)
return nil
}
diff --git a/internal/util/util_test.go b/internal/util/util_test.go
index dbeec62..bb76752 100644
--- a/internal/util/util_test.go
+++ b/internal/util/util_test.go
@@ -3,10 +3,9 @@ package util
import (
"bytes"
"testing"
- "time"
)
-func Test_EnsureValidURL(t *testing.T) {
+func TestEnsureValidURL(t *testing.T) {
_, validErr := EnsureValidURL("%notvalid%")
if validErr == nil {
@@ -39,7 +38,7 @@ func Test_EnsureValidURL(t *testing.T) {
}
}
-func Test_MakeRandomByteSlice(t *testing.T) {
+func TestMakeRandomByteSlice(t *testing.T) {
random, randomErr := MakeRandomByteSlice(32)
if randomErr != nil {
t.Fatalf("Got: %v, want: nil", randomErr)
@@ -58,7 +57,7 @@ func Test_MakeRandomByteSlice(t *testing.T) {
}
}
-func Test_WAYFEncode(t *testing.T) {
+func TestWAYFEncode(t *testing.T) {
// AuthTemplate
returnTo := "127.0.0.1:8000/test123bla/#wow "
@@ -70,7 +69,7 @@ func Test_WAYFEncode(t *testing.T) {
}
}
-func Test_ReplaceWAYF(t *testing.T) {
+func TestReplaceWAYF(t *testing.T) {
// We expect url encoding but the spaces to be correctly replace with a + instead of a %20
// And we expect that the return to and org_id are correctly replaced
replaced := ReplaceWAYF(
@@ -112,7 +111,7 @@ func Test_ReplaceWAYF(t *testing.T) {
}
}
-func Test_GetLanguageMatched(t *testing.T) {
+func TestGetLanguageMatched(t *testing.T) {
// exact match
returned := GetLanguageMatched(map[string]string{"en": "test", "de": "test2"}, "en")
if returned != "test" {
diff --git a/internal/verify/verify.go b/internal/verify/verify.go
index 2dd0472..6432619 100644
--- a/internal/verify/verify.go
+++ b/internal/verify/verify.go
@@ -7,7 +7,7 @@ import (
"github.com/jedisct1/go-minisign"
)
-// Verify verifies the signature (.minisig file format) on signedJson.
+// Verify verifies the signature (.minisig file format) on signedJSON.
//
// expectedFileName must be set to the file type to be verified, either "server_list.json" or "organization_list.json".
// minSign must be set to the minimum UNIX timestamp (without milliseconds) for the file version.
@@ -20,7 +20,7 @@ import (
// Verify is a wrapper around verifyWithKeys where allowedPublicKeys is set to the list from https://git.sr.ht/~eduvpn/disco.eduvpn.org#public-keys.
func Verify(
signatureFileContent string,
- signedJson []byte,
+ signedJSON []byte,
expectedFileName string,
minSignTime uint64,
forcePrehash bool,
@@ -32,7 +32,7 @@ func Verify(
}
valid, err := verifyWithKeys(
signatureFileContent,
- signedJson,
+ signedJSON,
expectedFileName,
minSignTime,
keyStrs,
@@ -44,7 +44,7 @@ func Verify(
return valid, nil
}
-// verifyWithKeys verifies the Minisign signature in signatureFileContent (minisig file format) over the server_list/organization_list JSON in signedJson.
+// verifyWithKeys verifies the Minisign signature in signatureFileContent (minisig file format) over the server_list/organization_list JSON in signedJSON.
//
// Verification is performed using a matching key in allowedPublicKeys.
// The signature is checked to be a Ed25519 Minisign (optionally Ed25519 Blake2b-512 prehashed, see forcePrehash) signature with a valid trusted comment.
@@ -56,7 +56,7 @@ func Verify(
// Note that every error path is wrapped in a custom type here because minisign does not return custom error types, they use errors.New
func verifyWithKeys(
signatureFileContent string,
- signedJson []byte,
+ signedJSON []byte,
filename string,
minSignTime uint64,
allowedPublicKeys []string,
@@ -97,7 +97,7 @@ func verifyWithKeys(
continue // Wrong key
}
- valid, err := key.Verify(signedJson, sig)
+ valid, err := key.Verify(signedJSON, sig)
if !valid {
return false, &VerifyInvalidSignatureError{Err: err}
}
diff --git a/internal/wireguard/wireguard.go b/internal/wireguard/wireguard.go
index 0a1ba5f..bbb22e4 100644
--- a/internal/wireguard/wireguard.go
+++ b/internal/wireguard/wireguard.go
@@ -22,14 +22,14 @@ func GenerateKey() (wgtypes.Key, error) {
// FIXME: Instead of doing a regex replace, decide if we should use a parser
func ConfigAddKey(config string, key wgtypes.Key) string {
- interface_section := "[Interface]"
- interface_section_escaped := regexp.QuoteMeta(interface_section)
+ interfaceSection := "[Interface]"
+ InterfaceSectionEscaped := regexp.QuoteMeta(interfaceSection)
// (?m) enables multi line mode
// ^ match from beginning of line
// $ match till end of line
// So it matches [Interface] section exactly
- interface_re := regexp.MustCompile(fmt.Sprintf("(?m)^%s$", interface_section_escaped))
- to_replace := fmt.Sprintf("%s\nPrivateKey = %s", interface_section, key.String())
- return interface_re.ReplaceAllString(config, to_replace)
+ InterfaceRe := regexp.MustCompile(fmt.Sprintf("(?m)^%s$", InterfaceSectionEscaped))
+ toReplace := fmt.Sprintf("%s\nPrivateKey = %s", interfaceSection, key.String())
+ return InterfaceRe.ReplaceAllString(config, toReplace)
}