diff options
| -rw-r--r-- | exports/exports.go | 334 | ||||
| -rw-r--r-- | internal/api/profiles/profiles.go | 10 | ||||
| -rw-r--r-- | internal/failover/monitor.go | 2 | ||||
| -rw-r--r-- | internal/server/server.go | 2 | ||||
| -rw-r--r-- | internal/wireguard/ini/ini_test.go | 116 | ||||
| -rw-r--r-- | types/cookie/cookie.go | 4 | ||||
| -rw-r--r-- | types/server/server_test.go | 25 |
7 files changed, 246 insertions, 247 deletions
diff --git a/exports/exports.go b/exports/exports.go index be56c81..cecdc4e 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -147,12 +147,12 @@ func getVPNState() (*client.Client, error) { // // Example Output: // -// { -// "message": { -// "en": "failed to register, a VPN state is already present" -// }, -// "misc": false -// } +// { +// "message": { +// "en": "failed to register, a VPN state is already present" +// }, +// "misc": false +// } // //export Register func Register( @@ -205,16 +205,17 @@ func Register( // ```ExpiryTimes()``` // // Example Output (1...4 are unix timestamps): -// { -// "start_time": 1, -// "end_time": 2, -// "button_time": 3, -// "countdown_time": 4, -// "notification_times": [ -// 1, -// 2, -// ], -// }, null +// +// { +// "start_time": 1, +// "end_time": 2, +// "button_time": 3, +// "countdown_time": 4, +// "notification_times": [ +// 1, +// 2, +// ], +// }, null // //export ExpiryTimes func ExpiryTimes() (*C.char, *C.char) { @@ -246,13 +247,12 @@ func ExpiryTimes() (*C.char, *C.char) { // // Example Output: // -// { -// "message": { -// "en": "failed to deregister" -// }, -// "misc": false -// } -// +// { +// "message": { +// "en": "failed to deregister" +// }, +// "misc": false +// } // //export Deregister func Deregister() *C.char { @@ -297,13 +297,12 @@ func Deregister() *C.char { // // Example Output: // -// { -// "message": { -// "en": "failed to add server" -// }, -// "misc": false -// } -// +// { +// "message": { +// "en": "failed to add server" +// }, +// "misc": false +// } // //export AddServer func AddServer(c C.uintptr_t, _type C.int, id *C.char, ni C.int) *C.char { @@ -339,12 +338,12 @@ func AddServer(c C.uintptr_t, _type C.int, id *C.char, ni C.int) *C.char { // // Example Output: // -// { -// "message": { -// "en": "failed to remove server" -// }, -// "misc": false -// } +// { +// "message": { +// "en": "failed to remove server" +// }, +// "misc": false +// } // //export RemoveServer func RemoveServer(_type C.int, id *C.char) *C.char { @@ -368,42 +367,43 @@ func RemoveServer(_type C.int, id *C.char) *C.char { // ```CurrentServer()``` // // Example Output: -// { -// "institute_access_server": { -// "display_name": { -// "en": "Demo" -// }, -// "identifier": "https://demo.eduvpn.nl/", -// "profiles": { -// "map": { -// "internet": { -// "display_name": { -// "en": "Internet" -// }, -// "supported_protocols": [ -// 1, -// 2 -// ] -// }, -// "internet-split": { -// "display_name": { -// "en": "No rfc1918 routes" -// }, -// "supported_protocols": [ -// 1, -// 2 -// ] -// } -// }, -// "current": "internet" -// }, -// "support_contacts": [ -// "mailto:eduvpn@surf.nl" -// ], -// "delisted": false -// }, -// "server_type": 1 -// }, null +// +// { +// "institute_access_server": { +// "display_name": { +// "en": "Demo" +// }, +// "identifier": "https://demo.eduvpn.nl/", +// "profiles": { +// "map": { +// "internet": { +// "display_name": { +// "en": "Internet" +// }, +// "supported_protocols": [ +// 1, +// 2 +// ] +// }, +// "internet-split": { +// "display_name": { +// "en": "No rfc1918 routes" +// }, +// "supported_protocols": [ +// 1, +// 2 +// ] +// } +// }, +// "current": "internet" +// }, +// "support_contacts": [ +// "mailto:eduvpn@surf.nl" +// ], +// "delisted": false +// }, +// "server_type": 1 +// }, null // //export CurrentServer func CurrentServer() (*C.char, *C.char) { @@ -434,24 +434,23 @@ func CurrentServer() (*C.char, *C.char) { // // Example Output (current profile here is empty as none has been chosen yet): // -// { -// "institute_access_servers": [ -// { -// "display_name": { -// "en": "Demo" -// }, -// "identifier": "https://demo.eduvpn.nl/", -// "profiles": { -// "current": "" -// }, -// "support_contacts": [ -// "mailto:eduvpn@surf.nl" -// ], -// "delisted": false -// } -// ] -// }, null -// +// { +// "institute_access_servers": [ +// { +// "display_name": { +// "en": "Demo" +// }, +// "identifier": "https://demo.eduvpn.nl/", +// "profiles": { +// "current": "" +// }, +// "support_contacts": [ +// "mailto:eduvpn@surf.nl" +// ], +// "delisted": false +// } +// ] +// }, null // //export ServerList func ServerList() (*C.char, *C.char) { @@ -555,11 +554,11 @@ func ServerList() (*C.char, *C.char) { // // Example Output (2=WireGuard): // -// { -// "config": "https://demo.eduvpn.nl/\n# Profile: ...\n# Expires: ...\n\n[Interface]\nPrivateKey = ...\nAddress = ...\nDNS = ...\n\n[Peer]\nPublicKey = ...=\nAllowedIPs = 0.0.0.0/0,::/0\nEndpoint = ...", -// "protocol": 2, -// "default_gateway": true -// } +// { +// "config": "https://demo.eduvpn.nl/\n# Profile: ...\n# Expires: ...\n\n[Interface]\nPrivateKey = ...\nAddress = ...\nDNS = ...\n\n[Peer]\nPublicKey = ...=\nAllowedIPs = 0.0.0.0/0,::/0\nEndpoint = ...", +// "protocol": 2, +// "default_gateway": true +// } // //export GetConfig func GetConfig(c C.uintptr_t, _type C.int, id *C.char, pTCP C.int, startup C.int) (*C.char, *C.char) { @@ -594,12 +593,12 @@ func GetConfig(c C.uintptr_t, _type C.int, id *C.char, pTCP C.int, startup C.int // // Example Output: // -// { -// "message": { -// "en": "profile does not exist" -// }, -// "misc": false -// } +// { +// "message": { +// "en": "profile does not exist" +// }, +// "misc": false +// } // //export SetProfileID func SetProfileID(data *C.char) *C.char { @@ -623,12 +622,12 @@ func SetProfileID(data *C.char) *C.char { // // Example Output: // -// { -// "message": { -// "en": "location does not exist" -// }, -// "misc": false -// } +// { +// "message": { +// "en": "location does not exist" +// }, +// "misc": false +// } // //export SetSecureLocation func SetSecureLocation(orgID *C.char, cc *C.char) *C.char { @@ -651,27 +650,27 @@ func SetSecureLocation(orgID *C.char, cc *C.char) *C.char { // // Example Output: // -// { -// "v": 1695291170, -// "server_list": [ -// { -// "base_url": "https://eduvpn.rash.al/", -// "country_code": "AL", -// "public_key_list": [ -// "k7.pub.S4j5JJiTEz1fWMkI.hzU_xJasWzD6Da2WR7hgbobx9n3o4XSDeqFh03tgM-0" -// ], -// "server_type": "secure_internet", -// "support_contact": [ -// "mailto:helpdesk@rash.al" -// ] -// }, -// { -// "base_url": "https://eduvpn.deic.dk/", -// "country_code": "DK", -// "public_key_list": [ -// "k7.pub.RNOJIYbemlfsE7EL.BxmV2l2UV7pCqz135ofBgyG9-xLg0R9rILQedZrfLtE" -// ], .................. -// } , null +// { +// "v": 1695291170, +// "server_list": [ +// { +// "base_url": "https://eduvpn.rash.al/", +// "country_code": "AL", +// "public_key_list": [ +// "k7.pub.S4j5JJiTEz1fWMkI.hzU_xJasWzD6Da2WR7hgbobx9n3o4XSDeqFh03tgM-0" +// ], +// "server_type": "secure_internet", +// "support_contact": [ +// "mailto:helpdesk@rash.al" +// ] +// }, +// { +// "base_url": "https://eduvpn.deic.dk/", +// "country_code": "DK", +// "public_key_list": [ +// "k7.pub.RNOJIYbemlfsE7EL.BxmV2l2UV7pCqz135ofBgyG9-xLg0R9rILQedZrfLtE" +// ], .................. +// } , null // //export DiscoServers func DiscoServers(c C.uintptr_t) (*C.char, *C.char) { @@ -704,32 +703,33 @@ func DiscoServers(c C.uintptr_t) (*C.char, *C.char) { // Example Input: ```DiscoOrganizations(myCookie)``` // // Example Output: -// { -// "v": 1695291170, -// "organization_list": [ -// { -// "display_name": { -// "en": "Academic Network of Albania - RASH" -// }, -// "org_id": "https://idp.rash.al/simplesaml/saml2/idp/metadata.php", -// "secure_internet_home": "https://eduvpn.rash.al/" -// }, -// { -// "display_name": { -// "da": "Dansk Sprognævn", -// "en": "Danish Language Council" -// }, -// "org_id": "http://idp.dsn.dk/adfs/services/trust", -// "secure_internet_home": "https://eduvpn.deic.dk/" -// }, -// { -// "display_name": { -// "da": "Erhvervsakademi Aarhus", -// "en": "Business Academy Aarhus" -// }, -// "org_id": "http://adfs.eaaa.dk/adfs/services/trust", -// "secure_inte ..................... -// }, null +// +// { +// "v": 1695291170, +// "organization_list": [ +// { +// "display_name": { +// "en": "Academic Network of Albania - RASH" +// }, +// "org_id": "https://idp.rash.al/simplesaml/saml2/idp/metadata.php", +// "secure_internet_home": "https://eduvpn.rash.al/" +// }, +// { +// "display_name": { +// "da": "Dansk Sprognævn", +// "en": "Danish Language Council" +// }, +// "org_id": "http://idp.dsn.dk/adfs/services/trust", +// "secure_internet_home": "https://eduvpn.deic.dk/" +// }, +// { +// "display_name": { +// "da": "Erhvervsakademi Aarhus", +// "en": "Business Academy Aarhus" +// }, +// "org_id": "http://adfs.eaaa.dk/adfs/services/trust", +// "secure_inte ..................... +// }, null // //export DiscoOrganizations func DiscoOrganizations(c C.uintptr_t) (*C.char, *C.char) { @@ -763,12 +763,13 @@ func DiscoOrganizations(c C.uintptr_t) (*C.char, *C.char) { // // Example Output: // -// { -// "message": { -// "en": "cleanup was not successful" -// }, -// "misc": false -// } +// { +// "message": { +// "en": "cleanup was not successful" +// }, +// "misc": false +// } +// //export Cleanup func Cleanup(c C.uintptr_t) *C.char { state, stateErr := getVPNState() @@ -794,12 +795,12 @@ func Cleanup(c C.uintptr_t) *C.char { // // Example Output: // -// { -// "message": { -// "en": "could not renew session" -// }, -// "misc": false -// } +// { +// "message": { +// "en": "could not renew session" +// }, +// "misc": false +// } // //export RenewSession func RenewSession(c C.uintptr_t) *C.char { @@ -824,7 +825,6 @@ func RenewSession(c C.uintptr_t) *C.char { // `support` thus indicates whether or not to enable WireGuard // An error is returned if this is not possible // -// //export SetSupportWireguard func SetSupportWireguard(support C.int) *C.char { state, stateErr := getVPNState() diff --git a/internal/api/profiles/profiles.go b/internal/api/profiles/profiles.go index 7b9dafc..111a835 100644 --- a/internal/api/profiles/profiles.go +++ b/internal/api/profiles/profiles.go @@ -6,12 +6,12 @@ import ( ) type Profile struct { - ID string `json:"profile_id"` - DisplayName string `json:"display_name"` - VPNProtoList []string `json:"vpn_proto_list"` + ID string `json:"profile_id"` + DisplayName string `json:"display_name"` + VPNProtoList []string `json:"vpn_proto_list"` VPNProtoTransportList []string `json:"vpn_proto_transport_list"` - DefaultGateway bool `json:"default_gateway"` - DNSSearchDomains []string `json:"dns_search_domain_list"` + DefaultGateway bool `json:"default_gateway"` + DNSSearchDomains []string `json:"dns_search_domain_list"` } type ListInfo struct { diff --git a/internal/failover/monitor.go b/internal/failover/monitor.go index 987cce6..d9028f2 100644 --- a/internal/failover/monitor.go +++ b/internal/failover/monitor.go @@ -1,9 +1,9 @@ package failover import ( - "fmt" "context" "errors" + "fmt" "time" "github.com/eduvpn/eduvpn-common/internal/log" diff --git a/internal/server/server.go b/internal/server/server.go index 1f73791..bffeb2c 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -150,7 +150,7 @@ func (s *Server) connect(ctx context.Context, wgSupport bool, pTCP bool) (*srvty Protocol: apicfg.Protocol, DefaultGateway: chosenP.DefaultGateway, DNSSearchDomains: chosenP.DNSSearchDomains, - ShouldFailover: chosenP.ShouldFailover(), + ShouldFailover: chosenP.ShouldFailover(), Proxy: proxy, }, nil } diff --git a/internal/wireguard/ini/ini_test.go b/internal/wireguard/ini/ini_test.go index 5382878..5168dda 100644 --- a/internal/wireguard/ini/ini_test.go +++ b/internal/wireguard/ini/ini_test.go @@ -8,20 +8,20 @@ import ( ) func TestShouldSkip(t *testing.T) { - cases := []struct{ - in string + cases := []struct { + in string want bool }{ { - in: "test", + in: "test", want: false, }, { - in: "#test", + in: "#test", want: true, }, { - in: "", + in: "", want: true, }, } @@ -35,25 +35,25 @@ func TestShouldSkip(t *testing.T) { } func TestIsSection(t *testing.T) { - cases := []struct{ - in string + cases := []struct { + in string want bool }{ { - in: "[test]", + in: "[test]", want: true, }, { - in: "#test", + in: "#test", want: false, }, { - in: "key=val", + in: "key=val", want: false, }, // sections with empty names will be ignored later { - in: "[]", + in: "[]", want: true, }, } @@ -67,24 +67,24 @@ func TestIsSection(t *testing.T) { } func TestSectionName(t *testing.T) { - cases := []struct{ - in string + cases := []struct { + in string want string }{ { - in: "[test]", + in: "[test]", want: "test", }, { - in: "[ spaces ]", + in: "[ spaces ]", want: "spaces", }, { - in: "[]", + in: "[]", want: "", }, { - in: "", + in: "", want: "", }, } @@ -98,52 +98,52 @@ func TestSectionName(t *testing.T) { } func TestKeyValue(t *testing.T) { - cases := []struct{ - in string - wantk string - wantv string + cases := []struct { + in string + wantk string + wantv string wanterr string }{ { - in: "bla", - wantk: "", - wantv: "", + in: "bla", + wantk: "", + wantv: "", wanterr: "no key/value found", }, { - in: "foo=bar", - wantk: "foo", - wantv: "bar", + in: "foo=bar", + wantk: "foo", + wantv: "bar", wanterr: "", }, { - in: " foo = bar ", - wantk: "foo", - wantv: "bar", + in: " foo = bar ", + wantk: "foo", + wantv: "bar", wanterr: "", }, { - in: "foo = bar", - wantk: "foo", - wantv: "bar", + in: "foo = bar", + wantk: "foo", + wantv: "bar", wanterr: "", }, { - in: "", - wantk: "", - wantv: "", + in: "", + wantk: "", + wantv: "", wanterr: "no key/value found", }, { - in: "=", - wantk: "", - wantv: "", + in: "=", + wantk: "", + wantv: "", wanterr: "key cannot be empty", }, { - in: "empty=", - wantk: "empty", - wantv: "", + in: "empty=", + wantk: "empty", + wantv: "", wanterr: "", }, } @@ -161,30 +161,30 @@ func TestKeyValue(t *testing.T) { } func TestOrderedKeysFind(t *testing.T) { - cases := []struct{ - v OrderedKeys + cases := []struct { + v OrderedKeys in string - w int + w int }{ { - v: []string{""}, + v: []string{""}, in: "test", - w: -1, + w: -1, }, { - v: []string{"bla"}, + v: []string{"bla"}, in: "bla", - w: 0, + w: 0, }, { - v: []string{"ha"}, + v: []string{"ha"}, in: "bla", - w: -1, + w: -1, }, { - v: []string{"ha", "ga"}, + v: []string{"ha", "ga"}, in: "ga", - w: 1, + w: 1, }, } @@ -197,23 +197,23 @@ func TestOrderedKeysFind(t *testing.T) { } func TestOrderedKeysRemove(t *testing.T) { - cases := []struct{ - v OrderedKeys + cases := []struct { + v OrderedKeys rem string out OrderedKeys }{ { - v: []string{"bla"}, + v: []string{"bla"}, rem: "test", out: []string{"bla"}, }, { - v: []string{"bla"}, + v: []string{"bla"}, rem: "bla", out: []string{}, }, { - v: []string{"ha", "ga"}, + v: []string{"ha", "ga"}, rem: "ga", out: []string{"ha"}, }, diff --git a/types/cookie/cookie.go b/types/cookie/cookie.go index 1582a9c..1714682 100644 --- a/types/cookie/cookie.go +++ b/types/cookie/cookie.go @@ -5,10 +5,10 @@ package cookie import ( - "fmt" "context" - "errors" "encoding/json" + "errors" + "fmt" "runtime/cgo" ) diff --git a/types/server/server_test.go b/types/server/server_test.go index 06a6851..f3c396d 100644 --- a/types/server/server_test.go +++ b/types/server/server_test.go @@ -13,62 +13,62 @@ func errorString(err error) string { } func TestServerUnmarshal(t *testing.T) { - cases := []struct{ - want Type + cases := []struct { + want Type wantErr string payload string }{ { - want: TypeUnknown, + want: TypeUnknown, wantErr: "invalid server type: a", payload: `{"value": "a"}`, }, { - want: TypeInstituteAccess, + want: TypeInstituteAccess, wantErr: "", payload: `{"value": "institute_access"}`, }, { - want: TypeCustom, + want: TypeCustom, wantErr: "", payload: `{"value": "custom_server"}`, }, { - want: TypeSecureInternet, + want: TypeSecureInternet, wantErr: "", payload: `{"value": "secure_internet"}`, }, { - want: TypeUnknown, + want: TypeUnknown, wantErr: "", payload: `{"value": 0}`, }, { - want: TypeInstituteAccess, + want: TypeInstituteAccess, wantErr: "", payload: `{"value": 1}`, }, { - want: TypeSecureInternet, + want: TypeSecureInternet, wantErr: "", payload: `{"value": 2}`, }, { - want: TypeCustom, + want: TypeCustom, wantErr: "", payload: `{"value": 3}`, }, // Values that are outside the range will be error checked too // This is thus even more strict than a regular type unmarshal/marshal { - want: TypeUnknown, + want: TypeUnknown, wantErr: "invalid server type: 25", payload: `{"value": 25}`, }, } for _, c := range cases { - var got struct{ + var got struct { Value Type `json:"value"` } err := json.Unmarshal([]byte(c.payload), &got) @@ -79,5 +79,4 @@ func TestServerUnmarshal(t *testing.T) { t.Fatalf("server unmarshal value is not equal to want, got: %v, want: %v", got.Value, c.want) } } - } |
