1
0
mirror of https://github.com/fumiama/go-nd-portal.git synced 2026-07-02 00:50:25 +08:00

refactor: auto get client ip from challenge response (#5)

* refactor: auto get client ip from challenge response
Since `outip()` was not working properly on devices getting local IP addresses behind a router, we should refactor this.
After analyzing the auth process, it is shown that  the challenge response includes key `client_ip` which is the real public IP address with key `ip` not specified in request.
- removed `outip()`
- added rsp key `ClientIP` to get client ip from challenge rsp

* style: trim code

* style: fix spelling issues

* refactor: create `portal_test.go` to handle portal tests separately

* feature: add `ResolveLocalClientIP()` and its test case

* optimize: resolve ClientIP locally when cant be get from challenge response
This commit is contained in:
chasey-dev
2025-09-01 22:33:57 +08:00
committed by GitHub
parent 32fdf3ae90
commit f2459dd8d9
5 changed files with 85 additions and 67 deletions

24
portal/portal_test.go Normal file
View File

@@ -0,0 +1,24 @@
package portal
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAutoSelectServerIP(t *testing.T) {
u, err := NewPortal("2000010101001", "12345678", "", "1.2.3.4", LoginTypeQshEdu)
if err != nil {
t.Fatal(err)
}
t.Log(u.sip)
assert.Equal(t, PortalServerIPQsh, u.sip)
}
func TestResolveLocalClientIP(t *testing.T) {
cip, err := ResolveLocalClientIP()
if err != nil {
t.Fatal(err)
}
t.Log(cip)
}