Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 53cc5c2328 | |||
| bd8ab00fa5 | |||
| 4fcc41eb8a | |||
| 34000962ef | |||
| 9d623ae3f9 | |||
| 6fd25387f7 | |||
| e8be839dac | |||
| d7ec5e852b | |||
| 4af011b91d | |||
| dc0a4af27f | |||
| 032b6e5096 | |||
| ae71b46482 | |||
| 7ecc56aa3c |
@@ -40,10 +40,10 @@ jobs:
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Docker Registry
|
||||
uses: docker/login-action@v4
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.fossy.my.id
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
@@ -79,7 +79,7 @@ jobs:
|
||||
fi
|
||||
|
||||
- name: Build and push Docker image (release)
|
||||
uses: docker/build-push-action@v7
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
@@ -97,7 +97,7 @@ jobs:
|
||||
if: steps.version.outputs.IS_PRERELEASE == 'false'
|
||||
|
||||
- name: Build and push Docker image (pre-release)
|
||||
uses: docker/build-push-action@v7
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.26.1-alpine AS go_builder
|
||||
FROM golang:1.26.0-alpine AS go_builder
|
||||
|
||||
ARG VERSION=dev
|
||||
ARG BUILD_DATE=unknown
|
||||
|
||||
@@ -3,37 +3,42 @@ module tunnel_pls
|
||||
go 1.26.0
|
||||
|
||||
require (
|
||||
charm.land/bubbles/v2 v2.0.0
|
||||
charm.land/bubbletea/v2 v2.0.2
|
||||
charm.land/lipgloss/v2 v2.0.1
|
||||
git.fossy.my.id/bagas/tunnel-please-grpc v1.5.0
|
||||
github.com/caddyserver/certmagic v0.25.2
|
||||
github.com/charmbracelet/colorprofile v0.4.3
|
||||
github.com/caddyserver/certmagic v0.25.1
|
||||
github.com/charmbracelet/bubbles v1.0.0
|
||||
github.com/charmbracelet/bubbletea v1.3.10
|
||||
github.com/charmbracelet/lipgloss v1.1.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/libdns/cloudflare v0.2.2
|
||||
github.com/muesli/termenv v0.16.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
golang.org/x/crypto v0.48.0
|
||||
google.golang.org/grpc v1.79.2
|
||||
google.golang.org/grpc v1.78.0
|
||||
google.golang.org/protobuf v1.36.11
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/atotto/clipboard v0.1.4 // indirect
|
||||
github.com/caddyserver/zerossl v0.1.5 // indirect
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8 // indirect
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/caddyserver/zerossl v0.1.4 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.4.1 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.11.6 // indirect
|
||||
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
|
||||
github.com/charmbracelet/x/term v0.2.2 // indirect
|
||||
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
||||
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.11.0 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.9.0 // indirect
|
||||
github.com/clipperhouse/stringish v0.1.1 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/libdns/libdns v1.1.1 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.20 // indirect
|
||||
github.com/mholt/acmez/v3 v3.1.6 // indirect
|
||||
github.com/miekg/dns v1.1.72 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.19 // indirect
|
||||
github.com/mholt/acmez/v3 v3.1.4 // indirect
|
||||
github.com/miekg/dns v1.1.69 // indirect
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
@@ -44,12 +49,12 @@ require (
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.1 // indirect
|
||||
go.uber.org/zap/exp v0.3.0 // indirect
|
||||
golang.org/x/mod v0.33.0 // indirect
|
||||
golang.org/x/net v0.50.0 // indirect
|
||||
golang.org/x/mod v0.32.0 // indirect
|
||||
golang.org/x/net v0.49.0 // indirect
|
||||
golang.org/x/sync v0.19.0 // indirect
|
||||
golang.org/x/sys v0.42.0 // indirect
|
||||
golang.org/x/sys v0.41.0 // indirect
|
||||
golang.org/x/text v0.34.0 // indirect
|
||||
golang.org/x/tools v0.42.0 // indirect
|
||||
golang.org/x/tools v0.41.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -1,51 +1,41 @@
|
||||
charm.land/bubbles/v2 v2.0.0 h1:tE3eK/pHjmtrDiRdoC9uGNLgpopOd8fjhEe31B/ai5s=
|
||||
charm.land/bubbles/v2 v2.0.0/go.mod h1:rCHoleP2XhU8um45NTuOWBPNVHxnkXKTiZqcclL/qOI=
|
||||
charm.land/bubbletea/v2 v2.0.1 h1:B8e9zzK7x9JJ+XvHGF4xnYu9Xa0E0y0MyggY6dbaCfQ=
|
||||
charm.land/bubbletea/v2 v2.0.1/go.mod h1:3LRff2U4WIYXy7MTxfbAQ+AdfM3D8Xuvz2wbsOD9OHQ=
|
||||
charm.land/bubbletea/v2 v2.0.2 h1:4CRtRnuZOdFDTWSff9r8QFt/9+z6Emubz3aDMnf/dx0=
|
||||
charm.land/bubbletea/v2 v2.0.2/go.mod h1:3LRff2U4WIYXy7MTxfbAQ+AdfM3D8Xuvz2wbsOD9OHQ=
|
||||
charm.land/lipgloss/v2 v2.0.0 h1:sd8N/B3x892oiOjFfBQdXBQp3cAkvjGaU5TvVZC3ivo=
|
||||
charm.land/lipgloss/v2 v2.0.0/go.mod h1:w6SnmsBFBmEFBodiEDurGS/sdUY/u1+v72DqUzc6J14=
|
||||
charm.land/lipgloss/v2 v2.0.1 h1:6Xzrn49+Py1Um5q/wZG1gWgER2+7dUyZ9XMEufqPSys=
|
||||
charm.land/lipgloss/v2 v2.0.1/go.mod h1:KjPle2Qd3YmvP1KL5OMHiHysGcNwq6u83MUjYkFvEkM=
|
||||
code.pfad.fr/check v1.1.0 h1:GWvjdzhSEgHvEHe2uJujDcpmZoySKuHQNrZMfzfO0bE=
|
||||
code.pfad.fr/check v1.1.0/go.mod h1:NiUH13DtYsb7xp5wll0U4SXx7KhXQVCtRgdC96IPfoM=
|
||||
git.fossy.my.id/bagas/tunnel-please-grpc v1.5.0 h1:3xszIhck4wo9CoeRq9vnkar4PhY7kz9QrR30qj2XszA=
|
||||
git.fossy.my.id/bagas/tunnel-please-grpc v1.5.0/go.mod h1:Weh6ZujgWmT8XxD3Qba7sJ6r5eyUMB9XSWynqdyOoLo=
|
||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/aymanbagabas/go-udiff v0.4.0 h1:TKnLPh7IbnizJIBKFWa9mKayRUBQ9Kh1BPCk6w2PnYM=
|
||||
github.com/aymanbagabas/go-udiff v0.4.0/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w=
|
||||
github.com/caddyserver/certmagic v0.25.2 h1:D7xcS7ggX/WEY54x0czj7ioTkmDWKIgxtIi2OcQclUc=
|
||||
github.com/caddyserver/certmagic v0.25.2/go.mod h1:llW/CvsNmza8S6hmsuggsZeiX+uS27dkqY27wDIuBWg=
|
||||
github.com/caddyserver/zerossl v0.1.5 h1:dkvOjBAEEtY6LIGAHei7sw2UgqSD6TrWweXpV7lvEvE=
|
||||
github.com/caddyserver/zerossl v0.1.5/go.mod h1:CxA0acn7oEGO6//4rtrRjYgEoa4MFw/XofZnrYwGqG4=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/charmbracelet/colorprofile v0.4.2 h1:BdSNuMjRbotnxHSfxy+PCSa4xAmz7szw70ktAtWRYrY=
|
||||
github.com/charmbracelet/colorprofile v0.4.2/go.mod h1:0rTi81QpwDElInthtrQ6Ni7cG0sDtwAd4C4le060fT8=
|
||||
github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q=
|
||||
github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8 h1:eyFRbAmexyt43hVfeyBofiGSEmJ7krjLOYt/9CF5NKA=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8/go.mod h1:SQpCTRNBtzJkwku5ye4S3HEuthAlGy2n9VXZnWkEW98=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||
github.com/aymanbagabas/go-udiff v0.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY=
|
||||
github.com/aymanbagabas/go-udiff v0.3.1/go.mod h1:G0fsKmG+P6ylD0r6N/KgQD/nWzgfnl8ZBcNLgcbrw8E=
|
||||
github.com/caddyserver/certmagic v0.25.1 h1:4sIKKbOt5pg6+sL7tEwymE1x2bj6CHr80da1CRRIPbY=
|
||||
github.com/caddyserver/certmagic v0.25.1/go.mod h1:VhyvndxtVton/Fo/wKhRoC46Rbw1fmjvQ3GjHYSQTEY=
|
||||
github.com/caddyserver/zerossl v0.1.4 h1:CVJOE3MZeFisCERZjkxIcsqIH4fnFdlYWnPYeFtBHRw=
|
||||
github.com/caddyserver/zerossl v0.1.4/go.mod h1:CxA0acn7oEGO6//4rtrRjYgEoa4MFw/XofZnrYwGqG4=
|
||||
github.com/charmbracelet/bubbles v1.0.0 h1:12J8/ak/uCZEMQ6KU7pcfwceyjLlWsDLAxB5fXonfvc=
|
||||
github.com/charmbracelet/bubbles v1.0.0/go.mod h1:9d/Zd5GdnauMI5ivUIVisuEm3ave1XwXtD1ckyV6r3E=
|
||||
github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
|
||||
github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
|
||||
github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk=
|
||||
github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
|
||||
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
|
||||
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
||||
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
|
||||
github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI=
|
||||
github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
|
||||
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
|
||||
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
|
||||
github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY=
|
||||
github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
|
||||
github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM=
|
||||
github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
|
||||
github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8=
|
||||
github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
|
||||
github.com/clipperhouse/displaywidth v0.9.0 h1:Qb4KOhYwRiN3viMv1v/3cTBlz3AcAZX3+y9OLhMtAtA=
|
||||
github.com/clipperhouse/displaywidth v0.9.0/go.mod h1:aCAAqTlh4GIVkhQnJpbL0T/WfcrJXHcj8C0yjYcjOZA=
|
||||
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
|
||||
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w94cO8U=
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-jose/go-jose/v4 v4.1.3 h1:CVLmWDhDVRa6Mi/IgCgaopNosCaHz7zrMeF9MlZRkrs=
|
||||
github.com/go-jose/go-jose/v4 v4.1.3/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
@@ -62,24 +52,28 @@ github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzh
|
||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/letsencrypt/challtestsrv v1.4.2 h1:0ON3ldMhZyWlfVNYYpFuWRTmZNnyfiL9Hh5YzC3JVwU=
|
||||
github.com/letsencrypt/challtestsrv v1.4.2/go.mod h1:GhqMqcSoeGpYd5zX5TgwA6er/1MbWzx/o7yuuVya+Wk=
|
||||
github.com/letsencrypt/pebble/v2 v2.10.0 h1:Wq6gYXlsY6ubqI3hhxsTzdyotvfdjFBxuwYqCLCnj/U=
|
||||
github.com/letsencrypt/pebble/v2 v2.10.0/go.mod h1:Sk8cmUIPcIdv2nINo+9PB4L+ZBhzY+F9A1a/h/xmWiQ=
|
||||
github.com/libdns/cloudflare v0.2.2 h1:XWHv+C1dDcApqazlh08Q6pjytYLgR2a+Y3xrXFu0vsI=
|
||||
github.com/libdns/cloudflare v0.2.2/go.mod h1:w9uTmRCDlAoafAsTPnn2nJ0XHK/eaUMh86DUk8BWi60=
|
||||
github.com/libdns/libdns v1.1.1 h1:wPrHrXILoSHKWJKGd0EiAVmiJbFShguILTg9leS/P/U=
|
||||
github.com/libdns/libdns v1.1.1/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-runewidth v0.0.20 h1:WcT52H91ZUAwy8+HUkdM3THM6gXqXuLJi9O3rjcQQaQ=
|
||||
github.com/mattn/go-runewidth v0.0.20/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
||||
github.com/mholt/acmez/v3 v3.1.6 h1:eGVQNObP0pBN4sxqrXeg7MYqTOWyoiYpQqITVWlrevk=
|
||||
github.com/mholt/acmez/v3 v3.1.6/go.mod h1:5nTPosTGosLxF3+LU4ygbgMRFDhbAVpqMI4+a4aHLBY=
|
||||
github.com/miekg/dns v1.1.72 h1:vhmr+TF2A3tuoGNkLDFK9zi36F2LS+hKTRW0Uf8kbzI=
|
||||
github.com/miekg/dns v1.1.72/go.mod h1:+EuEPhdHOsfk6Wk5TT2CzssZdqkmFhf8r+aVyDEToIs=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
||||
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
||||
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
|
||||
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
||||
github.com/mholt/acmez/v3 v3.1.4 h1:DyzZe/RnAzT3rpZj/2Ii5xZpiEvvYk3cQEN/RmqxwFQ=
|
||||
github.com/mholt/acmez/v3 v3.1.4/go.mod h1:L1wOU06KKvq7tswuMDwKdcHeKpFFgkppZy/y0DFxagQ=
|
||||
github.com/miekg/dns v1.1.69 h1:Kb7Y/1Jo+SG+a2GtfoFUfDkG//csdRPwRLkCsxDG9Sc=
|
||||
github.com/miekg/dns v1.1.69/go.mod h1:7OyjD9nEba5OkqQ/hB4fy3PIoxafSZJtducccIelz3g=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
||||
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
@@ -100,16 +94,16 @@ github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo=
|
||||
github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48=
|
||||
go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8=
|
||||
go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0=
|
||||
go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs=
|
||||
go.opentelemetry.io/otel/sdk v1.39.0 h1:nMLYcjVsvdui1B/4FRkwjzoRVsMK8uL/cj0OyhKzt18=
|
||||
go.opentelemetry.io/otel/sdk v1.39.0/go.mod h1:vDojkC4/jsTJsE+kh+LXYQlbL8CgrEcwmt1ENZszdJE=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.39.0 h1:cXMVVFVgsIf2YL6QkRF4Urbr/aMInf+2WKg+sEJTtB8=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.39.0/go.mod h1:xq9HEVH7qeX69/JnwEfp6fVq5wosJsY1mt4lLfYdVew=
|
||||
go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI=
|
||||
go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA=
|
||||
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
|
||||
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
|
||||
go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA=
|
||||
go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI=
|
||||
go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E=
|
||||
go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA=
|
||||
go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE=
|
||||
go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
@@ -122,28 +116,28 @@ golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
|
||||
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
||||
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
|
||||
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
|
||||
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
|
||||
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
|
||||
golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
|
||||
golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
|
||||
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
|
||||
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
|
||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
||||
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
|
||||
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg=
|
||||
golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM=
|
||||
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
||||
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
||||
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
|
||||
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
|
||||
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
|
||||
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
|
||||
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
||||
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b h1:Mv8VFug0MP9e5vUxfBcE3vUkV6CImK3cMNMIDFjmzxU=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251222181119-0a764e51fe1b/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ=
|
||||
google.golang.org/grpc v1.79.2 h1:fRMD94s2tITpyJGtBBn7MkMseNpOZU8ZxgC3MMBaXRU=
|
||||
google.golang.org/grpc v1.79.2/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
|
||||
google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc=
|
||||
google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U=
|
||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
"tunnel_pls/internal/port"
|
||||
"tunnel_pls/internal/random"
|
||||
"tunnel_pls/internal/registry"
|
||||
"tunnel_pls/internal/server"
|
||||
"tunnel_pls/internal/transport"
|
||||
"tunnel_pls/internal/types"
|
||||
"tunnel_pls/internal/version"
|
||||
"tunnel_pls/server"
|
||||
"tunnel_pls/types"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"tunnel_pls/internal/config"
|
||||
"tunnel_pls/internal/port"
|
||||
"tunnel_pls/internal/registry"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/session/slug"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package config
|
||||
|
||||
import "tunnel_pls/types"
|
||||
import (
|
||||
"tunnel_pls/internal/types"
|
||||
)
|
||||
|
||||
type Config interface {
|
||||
Domain() string
|
||||
|
||||
@@ -3,7 +3,7 @@ package config
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
@@ -32,7 +32,7 @@ type config struct {
|
||||
|
||||
bufferSize int
|
||||
headerSize int
|
||||
|
||||
|
||||
pprofEnabled bool
|
||||
pprofPort string
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
"tunnel_pls/internal/config"
|
||||
"tunnel_pls/internal/registry"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
proto "git.fossy.my.id/bagas/tunnel-please-grpc/gen"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
@@ -7,14 +7,13 @@ import (
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
"tunnel_pls/internal/session/forwarder"
|
||||
"tunnel_pls/internal/session/interaction"
|
||||
"tunnel_pls/internal/session/lifecycle"
|
||||
"tunnel_pls/internal/session/slug"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"tunnel_pls/internal/port"
|
||||
"tunnel_pls/internal/registry"
|
||||
"tunnel_pls/session/forwarder"
|
||||
"tunnel_pls/session/interaction"
|
||||
"tunnel_pls/session/lifecycle"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
|
||||
proto "git.fossy.my.id/bagas/tunnel-please-grpc/gen"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -885,16 +884,16 @@ func (m *mockLifecycle) Connection() ssh.Conn {
|
||||
return args.Get(0).(ssh.Conn)
|
||||
}
|
||||
func (m *mockLifecycle) User() string { return m.Called().String(0) }
|
||||
func (m *mockLifecycle) SetChannel(channel ssh.Channel) { m.Called(channel) }
|
||||
func (m *mockLifecycle) SetChannel(channel ssh.Channel) error { return m.Called(channel).Error(0) }
|
||||
func (m *mockLifecycle) SetStatus(status types.SessionStatus) { m.Called(status) }
|
||||
func (m *mockLifecycle) IsActive() bool { return m.Called().Bool(0) }
|
||||
func (m *mockLifecycle) StartedAt() time.Time { return m.Called().Get(0).(time.Time) }
|
||||
func (m *mockLifecycle) PortRegistry() port.Port {
|
||||
func (m *mockLifecycle) PortRegistry() lifecycle.PortRegistry {
|
||||
args := m.Called()
|
||||
if args.Get(0) == nil {
|
||||
return nil
|
||||
}
|
||||
return args.Get(0).(port.Port)
|
||||
return args.Get(0).(lifecycle.PortRegistry)
|
||||
}
|
||||
|
||||
type mockEventServiceClient struct {
|
||||
|
||||
+14
-11
@@ -33,10 +33,15 @@ func (pm *port) AddRange(startPort, endPort uint16) error {
|
||||
if startPort > endPort {
|
||||
return fmt.Errorf("start port cannot be greater than end port")
|
||||
}
|
||||
for index := startPort; index <= endPort; index++ {
|
||||
if _, exists := pm.ports[index]; !exists {
|
||||
pm.ports[index] = false
|
||||
pm.sortedPorts = append(pm.sortedPorts, index)
|
||||
for index := startPort; ; index++ {
|
||||
if index != 0 {
|
||||
if _, exists := pm.ports[index]; !exists {
|
||||
pm.ports[index] = false
|
||||
pm.sortedPorts = append(pm.sortedPorts, index)
|
||||
}
|
||||
}
|
||||
if index == endPort {
|
||||
break
|
||||
}
|
||||
}
|
||||
sort.Slice(pm.sortedPorts, func(i, j int) bool {
|
||||
@@ -51,6 +56,7 @@ func (pm *port) Unassigned() (uint16, bool) {
|
||||
|
||||
for _, index := range pm.sortedPorts {
|
||||
if !pm.ports[index] {
|
||||
pm.ports[index] = true
|
||||
return index, true
|
||||
}
|
||||
}
|
||||
@@ -61,6 +67,9 @@ func (pm *port) SetStatus(port uint16, assigned bool) error {
|
||||
pm.mu.Lock()
|
||||
defer pm.mu.Unlock()
|
||||
|
||||
if _, exists := pm.ports[port]; !exists {
|
||||
return fmt.Errorf("port %d is not in the allowed range", port)
|
||||
}
|
||||
pm.ports[port] = assigned
|
||||
return nil
|
||||
}
|
||||
@@ -70,16 +79,10 @@ func (pm *port) Claim(port uint16) (claimed bool) {
|
||||
defer pm.mu.Unlock()
|
||||
|
||||
status, exists := pm.ports[port]
|
||||
|
||||
if exists && status {
|
||||
if !exists || status {
|
||||
return false
|
||||
}
|
||||
|
||||
if !exists {
|
||||
pm.ports[port] = true
|
||||
return true
|
||||
}
|
||||
|
||||
pm.ports[port] = true
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ func TestAddRange(t *testing.T) {
|
||||
{"normal range", 1000, 1002, false},
|
||||
{"invalid range", 2000, 1999, true},
|
||||
{"single port range", 3000, 3000, false},
|
||||
{"range ending at max uint16", 65533, 65535, false},
|
||||
{"range including port zero", 0, 2, false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -31,6 +33,22 @@ func TestAddRange(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddRangeBoundaries(t *testing.T) {
|
||||
pm := New()
|
||||
err := pm.AddRange(0, 3)
|
||||
assert.NoError(t, err)
|
||||
_, hasZero := pm.(*port).ports[0]
|
||||
assert.False(t, hasZero, "port 0 must be skipped")
|
||||
assert.Len(t, pm.(*port).ports, 3)
|
||||
|
||||
pm2 := New()
|
||||
err = pm2.AddRange(65533, 65535)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, pm2.(*port).ports, 3)
|
||||
_, hasMax := pm2.(*port).ports[65535]
|
||||
assert.True(t, hasMax)
|
||||
}
|
||||
|
||||
func TestUnassigned(t *testing.T) {
|
||||
pm := New()
|
||||
_ = pm.AddRange(1000, 1002)
|
||||
@@ -58,6 +76,21 @@ func TestUnassigned(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnassignedReservesPort(t *testing.T) {
|
||||
pm := New()
|
||||
_ = pm.AddRange(1000, 1002)
|
||||
|
||||
p1, ok1 := pm.Unassigned()
|
||||
assert.True(t, ok1)
|
||||
assert.Equal(t, uint16(1000), p1)
|
||||
|
||||
p2, ok2 := pm.Unassigned()
|
||||
assert.True(t, ok2)
|
||||
assert.Equal(t, uint16(1001), p2)
|
||||
|
||||
assert.True(t, pm.(*port).ports[1000], "Unassigned must reserve the port")
|
||||
}
|
||||
|
||||
func TestSetStatus(t *testing.T) {
|
||||
pm := New()
|
||||
_ = pm.AddRange(1000, 1002)
|
||||
@@ -83,6 +116,17 @@ func TestSetStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetStatusUnknownPort(t *testing.T) {
|
||||
pm := New()
|
||||
_ = pm.AddRange(1000, 1002)
|
||||
|
||||
err := pm.SetStatus(5000, true)
|
||||
assert.Error(t, err)
|
||||
|
||||
_, exists := pm.(*port).ports[5000]
|
||||
assert.False(t, exists, "SetStatus must not create entries for unknown ports")
|
||||
}
|
||||
|
||||
func TestClaim(t *testing.T) {
|
||||
pm := New()
|
||||
_ = pm.AddRange(1000, 1002)
|
||||
@@ -95,7 +139,7 @@ func TestClaim(t *testing.T) {
|
||||
}{
|
||||
{"claim unassigned port", 1000, false, true},
|
||||
{"claim already assigned port", 1001, true, false},
|
||||
{"claim non-existent port", 5000, false, true},
|
||||
{"claim non-existent port", 5000, false, false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -107,8 +151,13 @@ func TestClaim(t *testing.T) {
|
||||
got := pm.Claim(tt.port)
|
||||
assert.Equal(t, tt.want, got)
|
||||
|
||||
finalState := pm.(*port).ports[tt.port]
|
||||
assert.True(t, finalState)
|
||||
finalState, exists := pm.(*port).ports[tt.port]
|
||||
if !tt.want && tt.port == 5000 {
|
||||
assert.False(t, exists, "out-of-range port must not be added to the registry")
|
||||
} else {
|
||||
assert.True(t, exists)
|
||||
assert.True(t, finalState)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ package registry
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"tunnel_pls/session/forwarder"
|
||||
"tunnel_pls/session/interaction"
|
||||
"tunnel_pls/session/lifecycle"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/session/forwarder"
|
||||
"tunnel_pls/internal/session/interaction"
|
||||
"tunnel_pls/internal/session/lifecycle"
|
||||
"tunnel_pls/internal/session/slug"
|
||||
"tunnel_pls/internal/types"
|
||||
)
|
||||
|
||||
type Key = types.SessionKey
|
||||
@@ -94,13 +94,13 @@ func (r *registry) Update(user string, oldKey, newKey Key) error {
|
||||
return ErrInvalidSlug
|
||||
}
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
if _, exists := r.slugIndex[newKey]; exists && newKey != oldKey {
|
||||
return ErrSlugInUse
|
||||
}
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
client, ok := r.byUser[user][oldKey]
|
||||
if !ok {
|
||||
return ErrSessionNotFound
|
||||
|
||||
@@ -4,12 +4,11 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
"tunnel_pls/internal/port"
|
||||
"tunnel_pls/session/forwarder"
|
||||
"tunnel_pls/session/interaction"
|
||||
"tunnel_pls/session/lifecycle"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/session/forwarder"
|
||||
"tunnel_pls/internal/session/interaction"
|
||||
"tunnel_pls/internal/session/lifecycle"
|
||||
"tunnel_pls/internal/session/slug"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
@@ -78,15 +77,15 @@ func (ml *mockLifecycle) Connection() ssh.Conn {
|
||||
return args.Get(0).(ssh.Conn)
|
||||
}
|
||||
|
||||
func (ml *mockLifecycle) PortRegistry() port.Port {
|
||||
func (ml *mockLifecycle) PortRegistry() lifecycle.PortRegistry {
|
||||
args := ml.Called()
|
||||
if args.Get(0) == nil {
|
||||
return nil
|
||||
}
|
||||
return args.Get(0).(port.Port)
|
||||
return args.Get(0).(lifecycle.PortRegistry)
|
||||
}
|
||||
|
||||
func (ml *mockLifecycle) SetChannel(channel ssh.Channel) { ml.Called(channel) }
|
||||
func (ml *mockLifecycle) SetChannel(channel ssh.Channel) error { return ml.Called(channel).Error(0) }
|
||||
func (ml *mockLifecycle) SetStatus(status types.SessionStatus) { ml.Called(status) }
|
||||
func (ml *mockLifecycle) IsActive() bool { return ml.Called().Bool(0) }
|
||||
func (ml *mockLifecycle) StartedAt() time.Time { return ml.Called().Get(0).(time.Time) }
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"tunnel_pls/internal/port"
|
||||
"tunnel_pls/internal/random"
|
||||
"tunnel_pls/internal/registry"
|
||||
"tunnel_pls/session"
|
||||
"tunnel_pls/internal/session"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
"tunnel_pls/internal/registry"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/session/slug"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
"tunnel_pls/internal/config"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/session/slug"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
@@ -28,6 +28,7 @@ type Forwarder interface {
|
||||
Close() error
|
||||
}
|
||||
type forwarder struct {
|
||||
mu sync.RWMutex
|
||||
listener net.Listener
|
||||
tunnelType types.TunnelType
|
||||
forwardedPort uint16
|
||||
@@ -60,7 +61,7 @@ func (f *forwarder) copyWithBuffer(dst io.Writer, src io.Reader) (written int64,
|
||||
}
|
||||
|
||||
func (f *forwarder) OpenForwardedChannel(ctx context.Context, origin net.Addr) (ssh.Channel, <-chan *ssh.Request, error) {
|
||||
payload := createForwardedTCPIPPayload(origin, f.forwardedPort)
|
||||
payload := createForwardedTCPIPPayload(origin, f.ForwardedPort())
|
||||
type channelResult struct {
|
||||
channel ssh.Channel
|
||||
reqs <-chan *ssh.Request
|
||||
@@ -141,32 +142,44 @@ func (f *forwarder) HandleConnection(dst io.ReadWriter, src ssh.Channel) {
|
||||
}
|
||||
|
||||
func (f *forwarder) SetType(tunnelType types.TunnelType) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
f.tunnelType = tunnelType
|
||||
}
|
||||
|
||||
func (f *forwarder) TunnelType() types.TunnelType {
|
||||
f.mu.RLock()
|
||||
defer f.mu.RUnlock()
|
||||
return f.tunnelType
|
||||
}
|
||||
|
||||
func (f *forwarder) ForwardedPort() uint16 {
|
||||
f.mu.RLock()
|
||||
defer f.mu.RUnlock()
|
||||
return f.forwardedPort
|
||||
}
|
||||
|
||||
func (f *forwarder) SetForwardedPort(port uint16) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
f.forwardedPort = port
|
||||
}
|
||||
|
||||
func (f *forwarder) SetListener(listener net.Listener) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
f.listener = listener
|
||||
}
|
||||
|
||||
func (f *forwarder) Listener() net.Listener {
|
||||
f.mu.RLock()
|
||||
defer f.mu.RUnlock()
|
||||
return f.listener
|
||||
}
|
||||
|
||||
func (f *forwarder) Close() error {
|
||||
if f.Listener() != nil {
|
||||
return f.listener.Close()
|
||||
if listener := f.Listener(); listener != nil {
|
||||
return listener.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/session/slug"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
@@ -3,14 +3,14 @@ package interaction
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
func (m *model) comingSoonUpdate(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
|
||||
func (m *model) comingSoonUpdate(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.showingComingSoon = false
|
||||
return m, textinput.Blink
|
||||
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
|
||||
}
|
||||
|
||||
func (m *model) comingSoonView() string {
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"charm.land/bubbles/v2/key"
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
func (m *model) handleCommandSelection(item commandItem) (tea.Model, tea.Cmd) {
|
||||
@@ -17,24 +17,24 @@ func (m *model) handleCommandSelection(item commandItem) (tea.Model, tea.Cmd) {
|
||||
m.editingSlug = true
|
||||
m.slugInput.SetValue(m.interaction.slug.String())
|
||||
m.slugInput.Focus()
|
||||
return m, textinput.Blink
|
||||
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
|
||||
case "tunnel-type":
|
||||
m.showingCommands = false
|
||||
m.showingComingSoon = true
|
||||
return m, tickCmd(5 * time.Second)
|
||||
return m, tea.Batch(tickCmd(5*time.Second), tea.ClearScreen, textinput.Blink)
|
||||
default:
|
||||
m.showingCommands = false
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *model) commandsUpdate(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
|
||||
func (m *model) commandsUpdate(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
|
||||
switch {
|
||||
case key.Matches(msg, m.keymap.quit), msg.String() == "esc":
|
||||
m.showingCommands = false
|
||||
return m, textinput.Blink
|
||||
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
|
||||
case msg.String() == "enter":
|
||||
selectedItem := m.commandList.SelectedItem()
|
||||
if selectedItem != nil {
|
||||
@@ -4,20 +4,20 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"charm.land/bubbles/v2/key"
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
func (m *model) dashboardUpdate(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
|
||||
func (m *model) dashboardUpdate(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
switch {
|
||||
case key.Matches(msg, m.keymap.quit):
|
||||
m.quitting = true
|
||||
return m, tea.Batch(textinput.Blink, tea.Quit)
|
||||
return m, tea.Batch(tea.ClearScreen, textinput.Blink, tea.Quit)
|
||||
case key.Matches(msg, m.keymap.command):
|
||||
m.showingCommands = true
|
||||
return m, textinput.Blink
|
||||
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@@ -6,15 +6,16 @@ import (
|
||||
"sync"
|
||||
"tunnel_pls/internal/config"
|
||||
"tunnel_pls/internal/random"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/session/slug"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"charm.land/bubbles/v2/help"
|
||||
"charm.land/bubbles/v2/key"
|
||||
"charm.land/bubbles/v2/list"
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/charmbracelet/colorprofile"
|
||||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/muesli/termenv"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
@@ -53,8 +54,6 @@ type interaction struct {
|
||||
cancel context.CancelFunc
|
||||
mode types.InteractiveMode
|
||||
programMu sync.Mutex
|
||||
width int
|
||||
height int
|
||||
}
|
||||
|
||||
func (i *interaction) SetMode(m types.InteractiveMode) {
|
||||
@@ -73,14 +72,8 @@ func (i *interaction) Send(message string) error {
|
||||
return nil
|
||||
}
|
||||
func (i *interaction) SetWH(w, h int) {
|
||||
i.programMu.Lock()
|
||||
i.width = w
|
||||
i.height = h
|
||||
prog := i.program
|
||||
i.programMu.Unlock()
|
||||
|
||||
if prog != nil {
|
||||
prog.Send(tea.WindowSizeMsg{
|
||||
if i.program != nil {
|
||||
i.program.Send(tea.WindowSizeMsg{
|
||||
Width: w,
|
||||
Height: h,
|
||||
})
|
||||
@@ -127,7 +120,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tickMsg:
|
||||
m.showingComingSoon = false
|
||||
return m, textinput.Blink
|
||||
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
|
||||
|
||||
case tea.WindowSizeMsg:
|
||||
m.width = msg.Width
|
||||
@@ -136,17 +129,17 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.commandList.SetHeight(msg.Height - 4)
|
||||
|
||||
if msg.Width < 80 {
|
||||
m.slugInput.SetWidth(msg.Width - 10)
|
||||
m.slugInput.Width = msg.Width - 10
|
||||
} else {
|
||||
m.slugInput.SetWidth(50)
|
||||
m.slugInput.Width = 50
|
||||
}
|
||||
return m, nil
|
||||
|
||||
case tea.QuitMsg:
|
||||
m.quitting = true
|
||||
return m, tea.Batch(textinput.Blink, tea.Quit)
|
||||
return m, tea.Batch(tea.ClearScreen, textinput.Blink, tea.Quit)
|
||||
|
||||
case tea.KeyPressMsg:
|
||||
case tea.KeyMsg:
|
||||
if m.showingComingSoon {
|
||||
return m.comingSoonUpdate(msg)
|
||||
}
|
||||
@@ -166,43 +159,36 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
func (i *interaction) Redraw() {
|
||||
i.programMu.Lock()
|
||||
prog := i.program
|
||||
w, h := i.width, i.height
|
||||
i.programMu.Unlock()
|
||||
|
||||
if prog != nil {
|
||||
prog.Send(tea.WindowSizeMsg{Width: w, Height: h})
|
||||
if i.program != nil {
|
||||
i.program.Send(tea.ClearScreen())
|
||||
}
|
||||
}
|
||||
|
||||
func (m *model) View() tea.View {
|
||||
func (m *model) View() string {
|
||||
if m.quitting {
|
||||
return tea.NewView("")
|
||||
return ""
|
||||
}
|
||||
|
||||
if m.showingComingSoon {
|
||||
return tea.NewView(m.comingSoonView())
|
||||
return m.comingSoonView()
|
||||
}
|
||||
|
||||
if m.editingSlug {
|
||||
return tea.NewView(m.slugView())
|
||||
return m.slugView()
|
||||
}
|
||||
|
||||
if m.showingCommands {
|
||||
return tea.NewView(m.commandsView())
|
||||
return m.commandsView()
|
||||
}
|
||||
|
||||
v := tea.NewView(m.dashboardView())
|
||||
v.AltScreen = true
|
||||
v.MouseMode = tea.MouseModeCellMotion
|
||||
return v
|
||||
return m.dashboardView()
|
||||
}
|
||||
|
||||
func (i *interaction) Start() {
|
||||
if i.mode == types.InteractiveModeHEADLESS {
|
||||
return
|
||||
}
|
||||
lipgloss.SetColorProfile(termenv.TrueColor)
|
||||
|
||||
protocol := "http"
|
||||
if i.config.TLSEnabled() {
|
||||
@@ -230,7 +216,7 @@ func (i *interaction) Start() {
|
||||
ti := textinput.New()
|
||||
ti.Placeholder = "my-custom-slug"
|
||||
ti.CharLimit = 20
|
||||
ti.SetWidth(50)
|
||||
ti.Width = 50
|
||||
|
||||
m := &model{
|
||||
randomizer: i.randomizer,
|
||||
@@ -259,29 +245,19 @@ func (i *interaction) Start() {
|
||||
}
|
||||
|
||||
i.programMu.Lock()
|
||||
w, h := i.width, i.height
|
||||
i.programMu.Unlock()
|
||||
|
||||
opts := []tea.ProgramOption{
|
||||
i.program = tea.NewProgram(
|
||||
m,
|
||||
tea.WithInput(i.channel),
|
||||
tea.WithOutput(i.channel),
|
||||
tea.WithColorProfile(colorprofile.TrueColor),
|
||||
tea.WithAltScreen(),
|
||||
tea.WithMouseCellMotion(),
|
||||
tea.WithoutSignals(),
|
||||
tea.WithoutSignalHandler(),
|
||||
tea.WithFPS(30),
|
||||
tea.WithEnvironment([]string{"TERM=xterm-256color", "COLORTERM=truecolor"}),
|
||||
}
|
||||
if w > 0 && h > 0 {
|
||||
opts = append(opts, tea.WithWindowSize(w, h))
|
||||
}
|
||||
|
||||
prog := tea.NewProgram(m, opts...)
|
||||
|
||||
i.programMu.Lock()
|
||||
i.program = prog
|
||||
)
|
||||
i.programMu.Unlock()
|
||||
|
||||
_, err := prog.Run()
|
||||
_, err := i.program.Run()
|
||||
if err != nil {
|
||||
log.Printf("Cannot close tea: %s \n", err)
|
||||
}
|
||||
+65
-69
@@ -7,12 +7,12 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"charm.land/bubbles/v2/key"
|
||||
"charm.land/bubbles/v2/list"
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"golang.org/x/crypto/ssh"
|
||||
@@ -459,7 +459,7 @@ func TestInteraction_Start(t *testing.T) {
|
||||
mockInteraction := New(mockRandom, mockConfig, mockSlug, mockForwarder, mockSessionRegistry, "user", mockCloser.Close)
|
||||
mockInteraction.SetMode(tt.mode)
|
||||
|
||||
mockConfig.On("Domain").Return("tunel.live")
|
||||
mockConfig.On("Domain").Return("tunnl.live")
|
||||
mockConfig.On("TLSEnabled").Return(tt.tlsEnabled)
|
||||
mockForwarder.On("TunnelType").Return(tt.tunnelType)
|
||||
mockForwarder.On("ForwardedPort").Return(tt.port)
|
||||
@@ -525,7 +525,7 @@ func TestModel_Update(t *testing.T) {
|
||||
|
||||
m := &model{
|
||||
randomizer: mockRandom,
|
||||
domain: "tunel.live",
|
||||
domain: "tunnl.live",
|
||||
protocol: "http",
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
port: 8080,
|
||||
@@ -622,7 +622,7 @@ func TestModel_View(t *testing.T) {
|
||||
|
||||
m := &model{
|
||||
randomizer: mockRandom,
|
||||
domain: "tunel.live",
|
||||
domain: "tunnl.live",
|
||||
protocol: "http",
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
port: 8080,
|
||||
@@ -651,9 +651,9 @@ func TestModel_View(t *testing.T) {
|
||||
view := m.View()
|
||||
|
||||
if tt.expectedEmpty {
|
||||
assert.Empty(t, view.Content)
|
||||
assert.Empty(t, view)
|
||||
} else {
|
||||
assert.NotEmpty(t, view.Content)
|
||||
assert.NotEmpty(t, view)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -694,7 +694,7 @@ func TestInteraction_Integration(t *testing.T) {
|
||||
func TestModel_Update_KeyMessages(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
key tea.KeyPressMsg
|
||||
key tea.KeyMsg
|
||||
showingComingSoon bool
|
||||
editingSlug bool
|
||||
showingCommands bool
|
||||
@@ -702,25 +702,25 @@ func TestModel_Update_KeyMessages(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "key press while showing coming soon",
|
||||
key: tea.KeyPressMsg{Code: tea.KeyEnter},
|
||||
key: tea.KeyMsg{Type: tea.KeyEnter},
|
||||
showingComingSoon: true,
|
||||
description: "should call comingSoonUpdate",
|
||||
},
|
||||
{
|
||||
name: "key press while editing slug",
|
||||
key: tea.KeyPressMsg{Code: tea.KeyEnter},
|
||||
key: tea.KeyMsg{Type: tea.KeyEnter},
|
||||
editingSlug: true,
|
||||
description: "should call slugUpdate",
|
||||
},
|
||||
{
|
||||
name: "key press while showing commands",
|
||||
key: tea.KeyPressMsg{Code: tea.KeyEnter},
|
||||
key: tea.KeyMsg{Type: tea.KeyEnter},
|
||||
showingCommands: true,
|
||||
description: "should call commandsUpdate",
|
||||
},
|
||||
{
|
||||
name: "key press in dashboard view",
|
||||
key: tea.KeyPressMsg{Code: 'c', Text: "c"},
|
||||
key: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'c'}},
|
||||
description: "should call dashboardUpdate",
|
||||
},
|
||||
}
|
||||
@@ -742,7 +742,7 @@ func TestModel_Update_KeyMessages(t *testing.T) {
|
||||
|
||||
m := &model{
|
||||
randomizer: mockRandom,
|
||||
domain: "tunel.live",
|
||||
domain: "tunnl.live",
|
||||
protocol: "http",
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
port: 8080,
|
||||
@@ -777,7 +777,7 @@ func TestModel_SlugUpdate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
tunnelType types.TunnelType
|
||||
keyMsg tea.KeyPressMsg
|
||||
keyMsg tea.KeyMsg
|
||||
inputValue string
|
||||
setupMocks func(*MockSessionRegistry, *MockSlug, *MockRandom)
|
||||
expectedEdit bool
|
||||
@@ -787,21 +787,21 @@ func TestModel_SlugUpdate(t *testing.T) {
|
||||
{
|
||||
name: "escape key cancels editing",
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
keyMsg: tea.KeyPressMsg{Code: tea.KeyEsc},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyEsc},
|
||||
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {},
|
||||
expectedEdit: false,
|
||||
},
|
||||
{
|
||||
name: "ctrl+c cancels editing",
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
keyMsg: tea.KeyPressMsg{Code: 'c', Mod: tea.ModCtrl},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyCtrlC},
|
||||
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {},
|
||||
expectedEdit: false,
|
||||
},
|
||||
{
|
||||
name: "enter key saves valid slug",
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
keyMsg: tea.KeyPressMsg{Code: tea.KeyEnter},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyEnter},
|
||||
inputValue: "my-custom-slug",
|
||||
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {
|
||||
ms.On("String").Return("old-slug")
|
||||
@@ -816,7 +816,7 @@ func TestModel_SlugUpdate(t *testing.T) {
|
||||
{
|
||||
name: "enter key with error shows error message",
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
keyMsg: tea.KeyPressMsg{Code: tea.KeyEnter},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyEnter},
|
||||
inputValue: "invalid",
|
||||
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {
|
||||
ms.On("String").Return("old-slug")
|
||||
@@ -831,7 +831,7 @@ func TestModel_SlugUpdate(t *testing.T) {
|
||||
{
|
||||
name: "ctrl+r generates random slug",
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
keyMsg: tea.KeyPressMsg{Code: 'r', Mod: tea.ModCtrl},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyCtrlR},
|
||||
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {
|
||||
mr.On("String", 20).Return("random-generated-slug", nil)
|
||||
},
|
||||
@@ -841,7 +841,7 @@ func TestModel_SlugUpdate(t *testing.T) {
|
||||
{
|
||||
name: "ctrl+r with error does nothing",
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
keyMsg: tea.KeyPressMsg{Code: 'r', Mod: tea.ModCtrl},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyCtrlR},
|
||||
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {
|
||||
mr.On("String", 20).Return("", assert.AnError)
|
||||
},
|
||||
@@ -850,14 +850,14 @@ func TestModel_SlugUpdate(t *testing.T) {
|
||||
{
|
||||
name: "regular key updates input",
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
keyMsg: tea.KeyPressMsg{Code: 'a', Text: "a"},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'a'}},
|
||||
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {},
|
||||
expectedEdit: true,
|
||||
},
|
||||
{
|
||||
name: "tcp tunnel exits editing immediately",
|
||||
tunnelType: types.TunnelTypeTCP,
|
||||
keyMsg: tea.KeyPressMsg{Code: 'a', Text: "a"},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'a'}},
|
||||
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {},
|
||||
expectedEdit: false,
|
||||
},
|
||||
@@ -879,7 +879,7 @@ func TestModel_SlugUpdate(t *testing.T) {
|
||||
|
||||
m := &model{
|
||||
randomizer: mockRandom,
|
||||
domain: "tunel.live",
|
||||
domain: "tunnl.live",
|
||||
protocol: "http",
|
||||
tunnelType: tt.tunnelType,
|
||||
port: 8080,
|
||||
@@ -986,7 +986,7 @@ func TestModel_SlugView(t *testing.T) {
|
||||
|
||||
m := &model{
|
||||
randomizer: mockRandom,
|
||||
domain: "tunel.live",
|
||||
domain: "tunnl.live",
|
||||
protocol: "http",
|
||||
tunnelType: tt.tunnelType,
|
||||
port: 8080,
|
||||
@@ -1006,19 +1006,19 @@ func TestModel_SlugView(t *testing.T) {
|
||||
func TestModel_ComingSoonUpdate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
keyMsg tea.KeyPressMsg
|
||||
keyMsg tea.KeyMsg
|
||||
}{
|
||||
{
|
||||
name: "any key dismisses coming soon",
|
||||
keyMsg: tea.KeyPressMsg{Code: tea.KeyEnter},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyEnter},
|
||||
},
|
||||
{
|
||||
name: "escape key dismisses",
|
||||
keyMsg: tea.KeyPressMsg{Code: tea.KeyEsc},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyEsc},
|
||||
},
|
||||
{
|
||||
name: "space key dismisses",
|
||||
keyMsg: tea.KeyPressMsg{Code: tea.KeySpace},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeySpace},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1097,7 +1097,7 @@ func TestModel_ComingSoonView(t *testing.T) {
|
||||
func TestModel_CommandsUpdate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
keyMsg tea.KeyPressMsg
|
||||
keyMsg tea.KeyMsg
|
||||
selectedItem list.Item
|
||||
expectCommands bool
|
||||
expectEditSlug bool
|
||||
@@ -1105,31 +1105,31 @@ func TestModel_CommandsUpdate(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "escape key closes commands",
|
||||
keyMsg: tea.KeyPressMsg{Code: tea.KeyEsc},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyEsc},
|
||||
expectCommands: false,
|
||||
},
|
||||
{
|
||||
name: "q key closes commands",
|
||||
keyMsg: tea.KeyPressMsg{Code: 'q', Text: "q"},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}},
|
||||
expectCommands: false,
|
||||
},
|
||||
{
|
||||
name: "enter on slug command starts editing",
|
||||
keyMsg: tea.KeyPressMsg{Code: tea.KeyEnter},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyEnter},
|
||||
selectedItem: commandItem{name: "slug", desc: "Set custom subdomain"},
|
||||
expectCommands: false,
|
||||
expectEditSlug: true,
|
||||
},
|
||||
{
|
||||
name: "enter on tunnel-type shows coming soon",
|
||||
keyMsg: tea.KeyPressMsg{Code: tea.KeyEnter},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyEnter},
|
||||
selectedItem: commandItem{name: "tunnel-type", desc: "Change tunnel type"},
|
||||
expectCommands: false,
|
||||
expectComingSoon: true,
|
||||
},
|
||||
{
|
||||
name: "arrow key navigates list",
|
||||
keyMsg: tea.KeyPressMsg{Code: tea.KeyDown},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyDown},
|
||||
expectCommands: true,
|
||||
},
|
||||
}
|
||||
@@ -1261,28 +1261,28 @@ func TestModel_CommandsView(t *testing.T) {
|
||||
func TestModel_DashboardUpdate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
keyMsg tea.KeyPressMsg
|
||||
keyMsg tea.KeyMsg
|
||||
expectQuit bool
|
||||
expectCommands bool
|
||||
}{
|
||||
{
|
||||
name: "q key quits",
|
||||
keyMsg: tea.KeyPressMsg{Code: 'q', Text: "q"},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}},
|
||||
expectQuit: true,
|
||||
},
|
||||
{
|
||||
name: "ctrl+c quits",
|
||||
keyMsg: tea.KeyPressMsg{Code: 'c', Mod: tea.ModCtrl},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyCtrlC},
|
||||
expectQuit: true,
|
||||
},
|
||||
{
|
||||
name: "c key opens commands",
|
||||
keyMsg: tea.KeyPressMsg{Code: 'c', Text: "c"},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'c'}},
|
||||
expectCommands: true,
|
||||
},
|
||||
{
|
||||
name: "other keys do nothing",
|
||||
keyMsg: tea.KeyPressMsg{Code: 'x', Text: "x"},
|
||||
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'x'}},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1398,7 +1398,7 @@ func TestModel_DashboardView(t *testing.T) {
|
||||
|
||||
m := &model{
|
||||
randomizer: mockRandom,
|
||||
domain: "tunel.live",
|
||||
domain: "tunnl.live",
|
||||
protocol: tt.protocol,
|
||||
tunnelType: tt.tunnelType,
|
||||
port: tt.port,
|
||||
@@ -1550,8 +1550,8 @@ func TestBuildURL(t *testing.T) {
|
||||
name: "http url",
|
||||
protocol: "http",
|
||||
subdomain: "test",
|
||||
domain: "tunel.live",
|
||||
expected: "http://test.tunel.live",
|
||||
domain: "tunnl.live",
|
||||
expected: "http://test.tunnl.live",
|
||||
},
|
||||
{
|
||||
name: "https url",
|
||||
@@ -1564,8 +1564,8 @@ func TestBuildURL(t *testing.T) {
|
||||
name: "custom subdomain",
|
||||
protocol: "http",
|
||||
subdomain: "my-custom-slug",
|
||||
domain: "tunel.live",
|
||||
expected: "http://my-custom-slug.tunel.live",
|
||||
domain: "tunnl.live",
|
||||
expected: "http://my-custom-slug.tunnl.live",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1712,30 +1712,30 @@ func TestModel_GetTunnelURL(t *testing.T) {
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
protocol: "http",
|
||||
slug: "my-app",
|
||||
domain: "tunel.live",
|
||||
expected: "http://my-app.tunel.live",
|
||||
domain: "tunnl.live",
|
||||
expected: "http://my-app.tunnl.live",
|
||||
},
|
||||
{
|
||||
name: "https tunnel",
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
protocol: "https",
|
||||
slug: "secure-app",
|
||||
domain: "tunel.live",
|
||||
expected: "https://secure-app.tunel.live",
|
||||
domain: "tunnl.live",
|
||||
expected: "https://secure-app.tunnl.live",
|
||||
},
|
||||
{
|
||||
name: "tcp tunnel",
|
||||
tunnelType: types.TunnelTypeTCP,
|
||||
domain: "tunel.live",
|
||||
domain: "tunnl.live",
|
||||
port: 8080,
|
||||
expected: "tcp://tunel.live:8080",
|
||||
expected: "tcp://tunnl.live:8080",
|
||||
},
|
||||
{
|
||||
name: "tcp tunnel with different port",
|
||||
tunnelType: types.TunnelTypeTCP,
|
||||
domain: "tunel.live",
|
||||
domain: "tunnl.live",
|
||||
port: 3306,
|
||||
expected: "tcp://tunel.live:3306",
|
||||
expected: "tcp://tunnl.live:3306",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1797,28 +1797,28 @@ func TestInteraction_Start_Interactive(t *testing.T) {
|
||||
tlsEnabled: false,
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
port: 8080,
|
||||
domain: "tunel.live",
|
||||
domain: "tunnl.live",
|
||||
},
|
||||
{
|
||||
name: "interactive mode with https",
|
||||
tlsEnabled: true,
|
||||
tunnelType: types.TunnelTypeHTTP,
|
||||
port: 8443,
|
||||
domain: "secure.tunel.live",
|
||||
domain: "secure.tunnl.live",
|
||||
},
|
||||
{
|
||||
name: "interactive mode with tcp",
|
||||
tlsEnabled: false,
|
||||
tunnelType: types.TunnelTypeTCP,
|
||||
port: 3306,
|
||||
domain: "db.tunel.live",
|
||||
domain: "db.tunnl.live",
|
||||
},
|
||||
{
|
||||
name: "interactive mode with tcp and tls enabled",
|
||||
tlsEnabled: true,
|
||||
tunnelType: types.TunnelTypeTCP,
|
||||
port: 5432,
|
||||
domain: "postgres.tunel.live",
|
||||
domain: "postgres.tunnl.live",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1901,7 +1901,7 @@ func TestInteraction_Start_ProtocolSelection(t *testing.T) {
|
||||
mockSessionRegistry := &MockSessionRegistry{}
|
||||
closeFunc := func() error { return nil }
|
||||
|
||||
mockConfig.On("Domain").Return("tunel.live")
|
||||
mockConfig.On("Domain").Return("tunnl.live")
|
||||
mockConfig.On("TLSEnabled").Return(tt.tlsEnabled)
|
||||
mockForwarder.On("TunnelType").Return(types.TunnelTypeHTTP)
|
||||
mockForwarder.On("ForwardedPort").Return(uint16(8080))
|
||||
@@ -1922,10 +1922,6 @@ func TestInteraction_Start_ProtocolSelection(t *testing.T) {
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
i := mockInteraction.(*interaction)
|
||||
if i.program != nil {
|
||||
assert.NotNil(t, i.program, "program should be initialized")
|
||||
}
|
||||
|
||||
i.Stop()
|
||||
|
||||
mockConfig.AssertExpectations(t)
|
||||
@@ -1966,7 +1962,7 @@ func TestInteraction_Stop(t *testing.T) {
|
||||
i := mockInteraction.(*interaction)
|
||||
|
||||
if tt.setupProgram {
|
||||
mockConfig.On("Domain").Return("tunel.live")
|
||||
mockConfig.On("Domain").Return("tunnl.live")
|
||||
mockConfig.On("TLSEnabled").Return(false)
|
||||
mockForwarder.On("TunnelType").Return(types.TunnelTypeHTTP)
|
||||
mockForwarder.On("ForwardedPort").Return(uint16(8080))
|
||||
@@ -2007,7 +2003,7 @@ func TestInteraction_Start_CommandListSetup(t *testing.T) {
|
||||
mockSessionRegistry := &MockSessionRegistry{}
|
||||
closeFunc := func() error { return nil }
|
||||
|
||||
mockConfig.On("Domain").Return("tunel.live")
|
||||
mockConfig.On("Domain").Return("tunnl.live")
|
||||
mockConfig.On("TLSEnabled").Return(false)
|
||||
mockForwarder.On("TunnelType").Return(types.TunnelTypeHTTP)
|
||||
mockForwarder.On("ForwardedPort").Return(uint16(8080))
|
||||
@@ -2043,7 +2039,7 @@ func TestInteraction_Start_TextInputSetup(t *testing.T) {
|
||||
mockSessionRegistry := &MockSessionRegistry{}
|
||||
closeFunc := func() error { return nil }
|
||||
|
||||
mockConfig.On("Domain").Return("tunel.live")
|
||||
mockConfig.On("Domain").Return("tunnl.live")
|
||||
mockConfig.On("TLSEnabled").Return(false)
|
||||
mockForwarder.On("TunnelType").Return(types.TunnelTypeHTTP)
|
||||
mockForwarder.On("ForwardedPort").Return(uint16(8080))
|
||||
@@ -2107,7 +2103,7 @@ func TestInteraction_Start_CleanupOnExit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
mockConfig.On("Domain").Return("tunel.live")
|
||||
mockConfig.On("Domain").Return("tunnl.live")
|
||||
mockConfig.On("TLSEnabled").Return(false)
|
||||
mockForwarder.On("TunnelType").Return(types.TunnelTypeHTTP)
|
||||
mockForwarder.On("ForwardedPort").Return(uint16(8080))
|
||||
@@ -2171,7 +2167,7 @@ func TestInteraction_Start_WithDifferentChannels(t *testing.T) {
|
||||
mockSessionRegistry := &MockSessionRegistry{}
|
||||
closeFunc := func() error { return nil }
|
||||
|
||||
mockConfig.On("Domain").Return("tunel.live")
|
||||
mockConfig.On("Domain").Return("tunnl.live")
|
||||
mockConfig.On("TLSEnabled").Return(false)
|
||||
mockForwarder.On("TunnelType").Return(types.TunnelTypeHTTP)
|
||||
mockForwarder.On("ForwardedPort").Return(uint16(8080))
|
||||
@@ -4,13 +4,13 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
"tunnel_pls/internal/random"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"charm.land/bubbles/v2/help"
|
||||
"charm.land/bubbles/v2/key"
|
||||
"charm.land/bubbles/v2/list"
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type commandItem struct {
|
||||
@@ -77,7 +77,7 @@ type keymap struct {
|
||||
type tickMsg time.Time
|
||||
|
||||
func (m *model) Init() tea.Cmd {
|
||||
return tea.Batch(textinput.Blink, tea.RequestWindowSize)
|
||||
return tea.Batch(textinput.Blink, tea.WindowSize())
|
||||
}
|
||||
|
||||
func getResponsiveWidth(screenWidth, padding, minWidth, maxWidth int) int {
|
||||
@@ -3,28 +3,28 @@ package interaction
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"charm.land/bubbles/v2/key"
|
||||
"charm.land/bubbles/v2/textinput"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
func (m *model) slugUpdate(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
|
||||
func (m *model) slugUpdate(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
|
||||
if m.tunnelType != types.TunnelTypeHTTP {
|
||||
m.editingSlug = false
|
||||
m.slugError = ""
|
||||
return m, textinput.Blink
|
||||
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
|
||||
}
|
||||
|
||||
switch msg.String() {
|
||||
case "esc", "ctrl+c":
|
||||
m.editingSlug = false
|
||||
m.slugError = ""
|
||||
return m, textinput.Blink
|
||||
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
|
||||
case "enter":
|
||||
inputValue := m.slugInput.Value()
|
||||
if err := m.interaction.sessionRegistry.Update(m.interaction.user, types.SessionKey{
|
||||
@@ -39,7 +39,7 @@ func (m *model) slugUpdate(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
m.editingSlug = false
|
||||
m.slugError = ""
|
||||
return m, textinput.Blink
|
||||
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
|
||||
default:
|
||||
if key.Matches(msg, m.keymap.random) {
|
||||
newSubdomain, err := m.randomizer.String(20)
|
||||
@@ -2,14 +2,13 @@ package lifecycle
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
portUtil "tunnel_pls/internal/port"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/session/slug"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
@@ -24,6 +23,12 @@ type SessionRegistry interface {
|
||||
Remove(key types.SessionKey)
|
||||
}
|
||||
|
||||
type PortRegistry interface {
|
||||
Unassigned() (uint16, bool)
|
||||
Claim(port uint16) bool
|
||||
SetStatus(port uint16, assigned bool) error
|
||||
}
|
||||
|
||||
type lifecycle struct {
|
||||
mu sync.Mutex
|
||||
status types.SessionStatus
|
||||
@@ -34,18 +39,18 @@ type lifecycle struct {
|
||||
slug slug.Slug
|
||||
startedAt time.Time
|
||||
sessionRegistry SessionRegistry
|
||||
portRegistry portUtil.Port
|
||||
portRegistry PortRegistry
|
||||
user string
|
||||
}
|
||||
|
||||
func New(conn ssh.Conn, forwarder Forwarder, slugManager slug.Slug, port portUtil.Port, sessionRegistry SessionRegistry, user string) Lifecycle {
|
||||
func New(conn ssh.Conn, forwarder Forwarder, slugManager slug.Slug, port PortRegistry, sessionRegistry SessionRegistry, user string) Lifecycle {
|
||||
return &lifecycle{
|
||||
status: types.SessionStatusINITIALIZING,
|
||||
conn: conn,
|
||||
channel: nil,
|
||||
forwarder: forwarder,
|
||||
slug: slugManager,
|
||||
startedAt: time.Now(),
|
||||
startedAt: time.Time{},
|
||||
sessionRegistry: sessionRegistry,
|
||||
portRegistry: port,
|
||||
user: user,
|
||||
@@ -55,16 +60,16 @@ func New(conn ssh.Conn, forwarder Forwarder, slugManager slug.Slug, port portUti
|
||||
type Lifecycle interface {
|
||||
Connection() ssh.Conn
|
||||
Channel() ssh.Channel
|
||||
PortRegistry() portUtil.Port
|
||||
PortRegistry() PortRegistry
|
||||
User() string
|
||||
SetChannel(channel ssh.Channel)
|
||||
SetChannel(channel ssh.Channel) error
|
||||
SetStatus(status types.SessionStatus)
|
||||
IsActive() bool
|
||||
StartedAt() time.Time
|
||||
Close() error
|
||||
}
|
||||
|
||||
func (l *lifecycle) PortRegistry() portUtil.Port {
|
||||
func (l *lifecycle) PortRegistry() PortRegistry {
|
||||
return l.portRegistry
|
||||
}
|
||||
|
||||
@@ -72,11 +77,25 @@ func (l *lifecycle) User() string {
|
||||
return l.user
|
||||
}
|
||||
|
||||
func (l *lifecycle) SetChannel(channel ssh.Channel) {
|
||||
func (l *lifecycle) SetChannel(channel ssh.Channel) error {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
if l.status == types.SessionStatusCLOSED {
|
||||
return fmt.Errorf("lifecycle is closed")
|
||||
}
|
||||
if channel == nil {
|
||||
return fmt.Errorf("channel cannot be nil")
|
||||
}
|
||||
if l.channel != nil {
|
||||
return fmt.Errorf("channel already set")
|
||||
}
|
||||
l.channel = channel
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *lifecycle) Channel() ssh.Channel {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.channel
|
||||
}
|
||||
|
||||
@@ -87,7 +106,13 @@ func (l *lifecycle) Connection() ssh.Conn {
|
||||
func (l *lifecycle) SetStatus(status types.SessionStatus) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
if l.status == types.SessionStatusCLOSED {
|
||||
return
|
||||
}
|
||||
l.status = status
|
||||
if status == types.SessionStatusRUNNING && l.startedAt.IsZero() {
|
||||
l.startedAt = time.Now()
|
||||
}
|
||||
}
|
||||
|
||||
func (l *lifecycle) IsActive() bool {
|
||||
@@ -98,50 +123,74 @@ func (l *lifecycle) IsActive() bool {
|
||||
|
||||
func (l *lifecycle) Close() error {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
if l.status == types.SessionStatusCLOSED {
|
||||
return l.closeErr
|
||||
closeErr := l.closeErr
|
||||
l.mu.Unlock()
|
||||
return closeErr
|
||||
}
|
||||
l.status = types.SessionStatusCLOSED
|
||||
|
||||
channel := l.channel
|
||||
conn := l.conn
|
||||
l.mu.Unlock()
|
||||
|
||||
var errs []error
|
||||
tunnelType := l.forwarder.TunnelType()
|
||||
|
||||
if l.channel != nil {
|
||||
if err := l.channel.Close(); err != nil && !isClosedError(err) {
|
||||
if channel != nil {
|
||||
if err := channel.Close(); err != nil && !isClosedError(err) {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
if conn != nil {
|
||||
if err := conn.Close(); err != nil && !isClosedError(err) {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
|
||||
if l.conn != nil {
|
||||
if err := l.conn.Close(); err != nil && !isClosedError(err) {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
l.cleanupRegistry()
|
||||
if err := l.cleanupForwarder(); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
clientSlug := l.slug.String()
|
||||
closeErr := errors.Join(errs...)
|
||||
|
||||
l.mu.Lock()
|
||||
l.closeErr = closeErr
|
||||
l.mu.Unlock()
|
||||
|
||||
return closeErr
|
||||
}
|
||||
|
||||
func (l *lifecycle) cleanupRegistry() {
|
||||
slugStr := l.slug.String()
|
||||
if slugStr == "" {
|
||||
return
|
||||
}
|
||||
key := types.SessionKey{
|
||||
Id: clientSlug,
|
||||
Type: tunnelType,
|
||||
Id: slugStr,
|
||||
Type: l.forwarder.TunnelType(),
|
||||
}
|
||||
l.sessionRegistry.Remove(key)
|
||||
}
|
||||
|
||||
if tunnelType == types.TunnelTypeTCP {
|
||||
errs = append(errs, l.PortRegistry().SetStatus(l.forwarder.ForwardedPort(), false))
|
||||
errs = append(errs, l.forwarder.Close())
|
||||
func (l *lifecycle) cleanupForwarder() error {
|
||||
if l.forwarder.TunnelType() != types.TunnelTypeTCP {
|
||||
return nil
|
||||
}
|
||||
|
||||
l.closeErr = errors.Join(errs...)
|
||||
return l.closeErr
|
||||
var errs []error
|
||||
errs = append(errs, l.portRegistry.SetStatus(l.forwarder.ForwardedPort(), false))
|
||||
errs = append(errs, l.forwarder.Close())
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
func isClosedError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
return errors.Is(err, io.EOF) || errors.Is(err, net.ErrClosed) || err.Error() == "EOF"
|
||||
return errors.Is(err, io.EOF) || errors.Is(err, net.ErrClosed)
|
||||
}
|
||||
|
||||
func (l *lifecycle) StartedAt() time.Time {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
return l.startedAt
|
||||
}
|
||||
+126
-5
@@ -5,8 +5,9 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
"testing"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
@@ -177,8 +178,14 @@ func TestLifecycle_SetChannel(t *testing.T) {
|
||||
|
||||
mockSSHChannel := &MockSSHChannel{}
|
||||
|
||||
mockLifecycle.SetChannel(mockSSHChannel)
|
||||
err := mockLifecycle.SetChannel(mockSSHChannel)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, mockSSHChannel, mockLifecycle.Channel())
|
||||
|
||||
anotherChannel := &MockSSHChannel{}
|
||||
err = mockLifecycle.SetChannel(anotherChannel)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "channel already set")
|
||||
assert.Equal(t, mockSSHChannel, mockLifecycle.Channel())
|
||||
}
|
||||
|
||||
@@ -276,14 +283,15 @@ func TestLifecycle_Close(t *testing.T) {
|
||||
mockLifecycle := New(mockSSHConn, mockForwarder, mockSlug, mockPort, mockSessionRegistry, "mas-fuad")
|
||||
|
||||
mockLifecycle.SetStatus(types.SessionStatusRUNNING)
|
||||
mockLifecycle.SetChannel(mockSSHChannel)
|
||||
err := mockLifecycle.SetChannel(mockSSHChannel)
|
||||
assert.NoError(t, err)
|
||||
|
||||
if tt.alreadyClosed {
|
||||
err := mockLifecycle.Close()
|
||||
err = mockLifecycle.Close()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
err := mockLifecycle.Close()
|
||||
err = mockLifecycle.Close()
|
||||
|
||||
if tt.expectErr {
|
||||
assert.Error(t, err)
|
||||
@@ -301,3 +309,116 @@ func TestLifecycle_Close(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLifecycle_ConcurrentClose(t *testing.T) {
|
||||
mockSSHConn := &MockSSHConn{}
|
||||
mockSSHConn.On("Close").Return(nil)
|
||||
|
||||
mockForwarder := &MockForwarder{}
|
||||
mockForwarder.On("TunnelType").Return(types.TunnelTypeHTTP)
|
||||
|
||||
mockSlug := &MockSlug{}
|
||||
mockSlug.On("String").Return("test-slug")
|
||||
|
||||
mockPort := &MockPort{}
|
||||
|
||||
mockSessionRegistry := &MockSessionRegistry{}
|
||||
mockSessionRegistry.On("Remove", mock.Anything).Return()
|
||||
|
||||
mockSSHChannel := &MockSSHChannel{}
|
||||
mockSSHChannel.On("Close").Return(nil)
|
||||
|
||||
mockLifecycle := New(mockSSHConn, mockForwarder, mockSlug, mockPort, mockSessionRegistry, "mas-fuad")
|
||||
mockLifecycle.SetStatus(types.SessionStatusRUNNING)
|
||||
err := mockLifecycle.SetChannel(mockSSHChannel)
|
||||
assert.NoError(t, err)
|
||||
|
||||
const numGoroutines = 10
|
||||
var wg sync.WaitGroup
|
||||
errChan := make(chan error, numGoroutines)
|
||||
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
err := mockLifecycle.Close()
|
||||
errChan <- err
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
close(errChan)
|
||||
|
||||
for err := range errChan {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.False(t, mockLifecycle.IsActive())
|
||||
}
|
||||
|
||||
func TestLifecycle_SetChannel_AfterClose(t *testing.T) {
|
||||
mockSSHConn := new(MockSSHConn)
|
||||
mockSSHConn.On("Close").Return(nil)
|
||||
mockForwarder := &MockForwarder{}
|
||||
mockForwarder.On("TunnelType").Return(types.TunnelTypeHTTP)
|
||||
mockSlug := &MockSlug{}
|
||||
mockSlug.On("String").Return("test-slug")
|
||||
mockPort := &MockPort{}
|
||||
mockSessionRegistry := &MockSessionRegistry{}
|
||||
mockSessionRegistry.On("Remove", mock.Anything).Return()
|
||||
mockSSHChannel := &MockSSHChannel{}
|
||||
mockSSHChannel.On("Close").Return(nil)
|
||||
|
||||
mockLifecycle := New(mockSSHConn, mockForwarder, mockSlug, mockPort, mockSessionRegistry, "mas-fuad")
|
||||
mockLifecycle.SetStatus(types.SessionStatusRUNNING)
|
||||
err := mockLifecycle.SetChannel(mockSSHChannel)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = mockLifecycle.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
anotherChannel := &MockSSHChannel{}
|
||||
err = mockLifecycle.SetChannel(anotherChannel)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "lifecycle is closed")
|
||||
}
|
||||
|
||||
func TestLifecycle_SetChannel_Nil(t *testing.T) {
|
||||
mockSSHConn := new(MockSSHConn)
|
||||
mockForwarder := &MockForwarder{}
|
||||
mockSlug := &MockSlug{}
|
||||
mockPort := &MockPort{}
|
||||
mockSessionRegistry := &MockSessionRegistry{}
|
||||
|
||||
mockLifecycle := New(mockSSHConn, mockForwarder, mockSlug, mockPort, mockSessionRegistry, "mas-fuad")
|
||||
|
||||
err := mockLifecycle.SetChannel(nil)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "channel cannot be nil")
|
||||
}
|
||||
|
||||
func TestLifecycle_SetStatus_AfterClose(t *testing.T) {
|
||||
mockSSHConn := new(MockSSHConn)
|
||||
mockSSHConn.On("Close").Return(nil)
|
||||
mockForwarder := &MockForwarder{}
|
||||
mockForwarder.On("TunnelType").Return(types.TunnelTypeHTTP)
|
||||
mockSlug := &MockSlug{}
|
||||
mockSlug.On("String").Return("test-slug")
|
||||
mockPort := &MockPort{}
|
||||
mockSessionRegistry := &MockSessionRegistry{}
|
||||
mockSessionRegistry.On("Remove", mock.Anything).Return()
|
||||
mockSSHChannel := &MockSSHChannel{}
|
||||
mockSSHChannel.On("Close").Return(nil)
|
||||
|
||||
mockLifecycle := New(mockSSHConn, mockForwarder, mockSlug, mockPort, mockSessionRegistry, "mas-fuad")
|
||||
mockLifecycle.SetStatus(types.SessionStatusRUNNING)
|
||||
err := mockLifecycle.SetChannel(mockSSHChannel)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = mockLifecycle.Close()
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, mockLifecycle.IsActive())
|
||||
|
||||
mockLifecycle.SetStatus(types.SessionStatusRUNNING)
|
||||
assert.False(t, mockLifecycle.IsActive(), "SetStatus should be ignored after Close")
|
||||
}
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
portUtil "tunnel_pls/internal/port"
|
||||
"tunnel_pls/internal/random"
|
||||
"tunnel_pls/internal/registry"
|
||||
"tunnel_pls/internal/session/forwarder"
|
||||
"tunnel_pls/internal/session/interaction"
|
||||
"tunnel_pls/internal/session/lifecycle"
|
||||
"tunnel_pls/internal/session/slug"
|
||||
"tunnel_pls/internal/transport"
|
||||
"tunnel_pls/session/forwarder"
|
||||
"tunnel_pls/session/interaction"
|
||||
"tunnel_pls/session/lifecycle"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
@@ -26,7 +26,7 @@ type Session interface {
|
||||
HandleGlobalRequest(ch <-chan *ssh.Request) error
|
||||
HandleTCPIPForward(req *ssh.Request) error
|
||||
HandleHTTPForward(req *ssh.Request, port uint16) error
|
||||
HandleTCPForward(req *ssh.Request, addr string, port uint16) error
|
||||
HandleTCPForward(req *ssh.Request, addr string, port uint16, reserved bool) error
|
||||
Lifecycle() lifecycle.Lifecycle
|
||||
Interaction() interaction.Interaction
|
||||
Forwarder() forwarder.Forwarder
|
||||
@@ -158,13 +158,15 @@ func (s *session) setupInteractiveMode(channel ssh.NewChannel) error {
|
||||
}
|
||||
|
||||
go func() {
|
||||
err = s.HandleGlobalRequest(reqs)
|
||||
err := s.HandleGlobalRequest(reqs)
|
||||
if err != nil {
|
||||
log.Printf("global request handler error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
s.lifecycle.SetChannel(ch)
|
||||
if err = s.lifecycle.SetChannel(ch); err != nil {
|
||||
return err
|
||||
}
|
||||
s.interaction.SetChannel(ch)
|
||||
s.interaction.SetMode(types.InteractiveModeINTERACTIVE)
|
||||
|
||||
@@ -198,23 +200,22 @@ func (s *session) waitForSessionEnd() error {
|
||||
}
|
||||
|
||||
func (s *session) waitForTCPIPForward() *ssh.Request {
|
||||
select {
|
||||
case req, ok := <-s.initialReq:
|
||||
if !ok {
|
||||
log.Println("Forwarding request channel closed")
|
||||
for {
|
||||
select {
|
||||
case req, ok := <-s.initialReq:
|
||||
if !ok {
|
||||
log.Println("Forwarding request channel closed")
|
||||
return nil
|
||||
}
|
||||
if req.Type == "tcpip-forward" {
|
||||
return req
|
||||
}
|
||||
log.Printf("Ignoring unexpected global request: %s", req.Type)
|
||||
_ = req.Reply(false, nil)
|
||||
case <-time.After(500 * time.Millisecond):
|
||||
log.Println("No tcpip-forward request received within timeout")
|
||||
return nil
|
||||
}
|
||||
if req.Type == "tcpip-forward" {
|
||||
return req
|
||||
}
|
||||
if err := req.Reply(false, nil); err != nil {
|
||||
log.Printf("Failed to reply to request: %v", err)
|
||||
}
|
||||
log.Printf("Expected tcpip-forward request, got: %s", req.Type)
|
||||
return nil
|
||||
case <-time.After(500 * time.Millisecond):
|
||||
log.Println("No forwarding request received")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,34 +233,13 @@ func (s *session) handleWindowChange(req *ssh.Request) error {
|
||||
return req.Reply(true, nil)
|
||||
}
|
||||
|
||||
func (s *session) handlePtyReq(req *ssh.Request) error {
|
||||
var ptyPayload struct {
|
||||
Term string
|
||||
Width uint32
|
||||
Height uint32
|
||||
PxW uint32
|
||||
PxH uint32
|
||||
Modes string
|
||||
}
|
||||
if err := ssh.Unmarshal(req.Payload, &ptyPayload); err == nil {
|
||||
if ptyPayload.Width > 0 && ptyPayload.Height > 0 {
|
||||
s.interaction.SetWH(int(ptyPayload.Width), int(ptyPayload.Height))
|
||||
}
|
||||
}
|
||||
return req.Reply(true, nil)
|
||||
}
|
||||
|
||||
func (s *session) HandleGlobalRequest(GlobalRequest <-chan *ssh.Request) error {
|
||||
for req := range GlobalRequest {
|
||||
switch req.Type {
|
||||
case "shell":
|
||||
case "shell", "pty-req":
|
||||
if err := req.Reply(true, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
case "pty-req":
|
||||
if err := s.handlePtyReq(req); err != nil {
|
||||
return err
|
||||
}
|
||||
case "window-change":
|
||||
if err := s.handleWindowChange(req); err != nil {
|
||||
return err
|
||||
@@ -274,35 +254,35 @@ func (s *session) HandleGlobalRequest(GlobalRequest <-chan *ssh.Request) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *session) parseForwardPayload(payload []byte) (address string, port uint16, err error) {
|
||||
func (s *session) parseForwardPayload(payload []byte) (address string, port uint16, reserved bool, err error) {
|
||||
var forwardPayload struct {
|
||||
BindAddr string
|
||||
BindPort uint32
|
||||
}
|
||||
|
||||
if err = ssh.Unmarshal(payload, &forwardPayload); err != nil {
|
||||
return "", 0, fmt.Errorf("failed to unmarshal forward payload: %w", err)
|
||||
return "", 0, false, fmt.Errorf("failed to unmarshal forward payload: %w", err)
|
||||
}
|
||||
|
||||
if forwardPayload.BindPort > 65535 {
|
||||
return "", 0, fmt.Errorf("port is larger than allowed port of 65535")
|
||||
return "", 0, false, fmt.Errorf("port is larger than allowed port of 65535")
|
||||
}
|
||||
|
||||
port = uint16(forwardPayload.BindPort)
|
||||
|
||||
if isBlockedPort(port) {
|
||||
return "", 0, fmt.Errorf("port is blocked")
|
||||
return "", 0, false, fmt.Errorf("port is blocked")
|
||||
}
|
||||
|
||||
if port == 0 {
|
||||
unassigned, ok := s.lifecycle.PortRegistry().Unassigned()
|
||||
if !ok {
|
||||
return "", 0, fmt.Errorf("no available port")
|
||||
return "", 0, false, fmt.Errorf("no available port")
|
||||
}
|
||||
return forwardPayload.BindAddr, unassigned, nil
|
||||
return forwardPayload.BindAddr, unassigned, true, nil
|
||||
}
|
||||
|
||||
return forwardPayload.BindAddr, port, nil
|
||||
return forwardPayload.BindAddr, port, false, nil
|
||||
}
|
||||
|
||||
func (s *session) denyForwardingRequest(req *ssh.Request, key *types.SessionKey, listener io.Closer, msg string) error {
|
||||
@@ -346,7 +326,7 @@ func (s *session) finalizeForwarding(req *ssh.Request, portToBind uint16, listen
|
||||
}
|
||||
|
||||
func (s *session) HandleTCPIPForward(req *ssh.Request) error {
|
||||
address, port, err := s.parseForwardPayload(req.Payload)
|
||||
address, port, reserved, err := s.parseForwardPayload(req.Payload)
|
||||
if err != nil {
|
||||
return s.denyForwardingRequest(req, nil, nil, fmt.Sprintf("cannot parse forwarded payload: %s", err.Error()))
|
||||
}
|
||||
@@ -355,7 +335,7 @@ func (s *session) HandleTCPIPForward(req *ssh.Request) error {
|
||||
case 80, 443:
|
||||
return s.HandleHTTPForward(req, port)
|
||||
default:
|
||||
return s.HandleTCPForward(req, address, port)
|
||||
return s.HandleTCPForward(req, address, port, reserved)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,30 +356,40 @@ func (s *session) HandleHTTPForward(req *ssh.Request, portToBind uint16) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *session) HandleTCPForward(req *ssh.Request, addr string, portToBind uint16) error {
|
||||
if claimed := s.lifecycle.PortRegistry().Claim(portToBind); !claimed {
|
||||
return s.denyForwardingRequest(req, nil, nil, fmt.Sprintf("Port %d is already in use or restricted", portToBind))
|
||||
func (s *session) HandleTCPForward(req *ssh.Request, addr string, portToBind uint16, reserved bool) error {
|
||||
if !reserved {
|
||||
if claimed := s.lifecycle.PortRegistry().Claim(portToBind); !claimed {
|
||||
return s.denyForwardingRequest(req, nil, nil, fmt.Sprintf("Port %d is already in use or restricted", portToBind))
|
||||
}
|
||||
}
|
||||
|
||||
releasePort := func() {
|
||||
if err := s.lifecycle.PortRegistry().SetStatus(portToBind, false); err != nil {
|
||||
log.Printf("failed to release port %d: %v", portToBind, err)
|
||||
}
|
||||
}
|
||||
|
||||
tcpServer := transport.NewTCPServer(portToBind, s.forwarder)
|
||||
listener, err := tcpServer.Listen()
|
||||
if err != nil {
|
||||
releasePort()
|
||||
return s.denyForwardingRequest(req, nil, listener, fmt.Sprintf("Port %d is already in use or restricted", portToBind))
|
||||
}
|
||||
|
||||
key := types.SessionKey{Id: fmt.Sprintf("%d", portToBind), Type: types.TunnelTypeTCP}
|
||||
if !s.registry.Register(key, s) {
|
||||
releasePort()
|
||||
return s.denyForwardingRequest(req, nil, listener, fmt.Sprintf("Failed to register TunnelTypeTCP client with id: %s", key.Id))
|
||||
}
|
||||
|
||||
err = s.finalizeForwarding(req, portToBind, listener, types.TunnelTypeTCP, key.Id)
|
||||
if err != nil {
|
||||
releasePort()
|
||||
return s.denyForwardingRequest(req, &key, listener, fmt.Sprintf("Failed to finalize forwarding: %s", err))
|
||||
}
|
||||
|
||||
go func() {
|
||||
err = tcpServer.Serve(listener)
|
||||
if err != nil {
|
||||
if err := tcpServer.Serve(listener); err != nil {
|
||||
log.Printf("Failed serving tcp server: %s\n", err)
|
||||
}
|
||||
}()
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
"time"
|
||||
"tunnel_pls/internal/config"
|
||||
"tunnel_pls/internal/registry"
|
||||
"tunnel_pls/session/lifecycle"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/session/lifecycle"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
@@ -396,6 +396,12 @@ func TestHandleTCPIPForward_Table(t *testing.T) {
|
||||
err := s.HandleTCPIPForward(req)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, uint16(12345), s.forwarder.ForwardedPort())
|
||||
|
||||
defer func() {
|
||||
if l := s.forwarder.Listener(); l != nil {
|
||||
_ = l.Close()
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
t.Run("Invalid Payload", func(t *testing.T) {
|
||||
@@ -699,6 +705,7 @@ func TestForwardingFailures(t *testing.T) {
|
||||
s, mRegistry, mPort, _, _, sReqs, cConn, cleanup := setup(t)
|
||||
defer cleanup()
|
||||
mPort.On("Claim", mock.Anything).Return(true)
|
||||
mPort.On("SetStatus", uint16(1234), false).Return(nil)
|
||||
mRegistry.On("Register", mock.Anything, mock.Anything).Return(false)
|
||||
|
||||
payload := make([]byte, 4+9+4)
|
||||
@@ -717,7 +724,7 @@ func TestForwardingFailures(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Finalize Forwarding Failure", func(t *testing.T) {
|
||||
s, mRegistry, _, mRandom, _, sReqs, cConn, cleanup := setup(t)
|
||||
s, mRegistry, _, mRandom, sConn, sReqs, cConn, cleanup := setup(t)
|
||||
defer cleanup()
|
||||
mRandom.On("String", 20).Return("test-slug", nil)
|
||||
mRegistry.On("Register", mock.Anything, mock.Anything).Return(true)
|
||||
@@ -736,7 +743,7 @@ func TestForwardingFailures(t *testing.T) {
|
||||
err := cConn.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
_ = sConn.Wait()
|
||||
|
||||
err = s.HandleTCPIPForward(req)
|
||||
assert.Error(t, err)
|
||||
@@ -758,6 +765,7 @@ func TestForwardingFailures(t *testing.T) {
|
||||
}(l)
|
||||
_, portStr, _ := net.SplitHostPort(l.Addr().String())
|
||||
port, _ := strconv.Atoi(portStr)
|
||||
mPort.On("SetStatus", uint16(port), false).Return(nil)
|
||||
|
||||
payload := make([]byte, 4+9+4)
|
||||
binary.BigEndian.PutUint32(payload[0:4], 9)
|
||||
@@ -807,7 +815,7 @@ func (m *mockNewChanFail) Accept() (ssh.Channel, <-chan *ssh.Request, error) {
|
||||
}
|
||||
|
||||
func TestWaitForTCPIPForward_EdgeCases(t *testing.T) {
|
||||
t.Run("Wrong Request Type", func(t *testing.T) {
|
||||
t.Run("Wrong Request Type Then Timeout", func(t *testing.T) {
|
||||
_, sReqs, _, cConn, cleanup := setupSSH(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -817,10 +825,65 @@ func TestWaitForTCPIPForward_EdgeCases(t *testing.T) {
|
||||
_, _, _ = cConn.SendRequest("not-tcpip-forward", true, nil)
|
||||
}()
|
||||
|
||||
start := time.Now()
|
||||
req := s.waitForTCPIPForward()
|
||||
elapsed := time.Since(start)
|
||||
|
||||
if req != nil {
|
||||
t.Error("expected nil request")
|
||||
}
|
||||
if elapsed < 400*time.Millisecond {
|
||||
t.Errorf("expected timeout ~500ms, got %v", elapsed)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Multiple Non-Forward Requests Then Success", func(t *testing.T) {
|
||||
_, sReqs, _, cConn, cleanup := setupSSH(t)
|
||||
defer cleanup()
|
||||
|
||||
s := &session{initialReq: sReqs}
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
_, _, _ = cConn.SendRequest("keepalive@openssh.com", false, nil)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
_, _, _ = cConn.SendRequest("hostkeys-00@openssh.com", false, nil)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
_, _, _ = cConn.SendRequest("tcpip-forward", true, nil)
|
||||
}()
|
||||
|
||||
req := s.waitForTCPIPForward()
|
||||
if req == nil {
|
||||
t.Error("expected tcpip-forward request, got nil")
|
||||
}
|
||||
if req != nil && req.Type != "tcpip-forward" {
|
||||
t.Errorf("expected tcpip-forward, got %s", req.Type)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Timeout After Non-Forward Requests", func(t *testing.T) {
|
||||
_, sReqs, _, cConn, cleanup := setupSSH(t)
|
||||
defer cleanup()
|
||||
|
||||
s := &session{initialReq: sReqs}
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
_, _, _ = cConn.SendRequest("keepalive@openssh.com", false, nil)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
_, _, _ = cConn.SendRequest("hostkeys-00@openssh.com", false, nil)
|
||||
}()
|
||||
|
||||
start := time.Now()
|
||||
req := s.waitForTCPIPForward()
|
||||
elapsed := time.Since(start)
|
||||
|
||||
if req != nil {
|
||||
t.Error("expected nil request after timeout")
|
||||
}
|
||||
if elapsed < 400*time.Millisecond {
|
||||
t.Errorf("expected timeout ~500ms after last request, got %v", elapsed)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Channel Closed", func(t *testing.T) {
|
||||
@@ -982,7 +1045,7 @@ func TestParseForwardPayload_Errors(t *testing.T) {
|
||||
s := &session{}
|
||||
|
||||
t.Run("Short Address", func(t *testing.T) {
|
||||
_, _, err := s.parseForwardPayload([]byte{0, 0, 0, 4})
|
||||
_, _, _, err := s.parseForwardPayload([]byte{0, 0, 0, 4})
|
||||
if err == nil {
|
||||
t.Error("expected error, got nil")
|
||||
}
|
||||
@@ -990,7 +1053,7 @@ func TestParseForwardPayload_Errors(t *testing.T) {
|
||||
|
||||
t.Run("Short Port", func(t *testing.T) {
|
||||
payload := append([]byte{0, 0, 0, 4}, []byte("addr")...)
|
||||
_, _, err := s.parseForwardPayload(payload)
|
||||
_, _, _, err := s.parseForwardPayload(payload)
|
||||
if err == nil {
|
||||
t.Error("expected error, got nil")
|
||||
}
|
||||
@@ -1001,7 +1064,7 @@ func TestParseForwardPayload_Errors(t *testing.T) {
|
||||
portBuf := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(portBuf, 22)
|
||||
payload = append(payload, portBuf...)
|
||||
_, _, err := s.parseForwardPayload(payload)
|
||||
_, _, _, err := s.parseForwardPayload(payload)
|
||||
if err == nil {
|
||||
t.Error("expected error, got nil")
|
||||
} else if !strings.Contains(err.Error(), "port is block") {
|
||||
@@ -1165,7 +1228,7 @@ func TestHandleTCPForward_Failures(t *testing.T) {
|
||||
s, _, mPort, _, sReqs, cConn, cleanup := setup(t)
|
||||
defer cleanup()
|
||||
mPort.On("Claim", mock.Anything).Return(false)
|
||||
err := s.HandleTCPForward(getReq(t, cConn, sReqs), "localhost", 1234)
|
||||
err := s.HandleTCPForward(getReq(t, cConn, sReqs), "localhost", 1234, false)
|
||||
if err == nil {
|
||||
t.Error("expected error, got nil")
|
||||
} else if !strings.Contains(err.Error(), "already in use") {
|
||||
@@ -1186,44 +1249,50 @@ func TestHandleTCPForward_Failures(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}(l)
|
||||
port := uint16(l.Addr().(*net.TCPAddr).Port)
|
||||
mPort.On("SetStatus", port, false).Return(nil)
|
||||
|
||||
err = s.HandleTCPForward(getReq(t, cConn, sReqs), "localhost", port)
|
||||
err = s.HandleTCPForward(getReq(t, cConn, sReqs), "localhost", port, false)
|
||||
if err == nil {
|
||||
t.Error("expected error, got nil")
|
||||
} else if !strings.Contains(err.Error(), "already in use") {
|
||||
t.Errorf("expected error to contain %q, got %q", "already in use", err.Error())
|
||||
}
|
||||
mPort.AssertExpectations(t)
|
||||
})
|
||||
|
||||
t.Run("Registry Register fail", func(t *testing.T) {
|
||||
s, mRegistry, mPort, _, sReqs, cConn, cleanup := setup(t)
|
||||
defer cleanup()
|
||||
mPort.On("Claim", mock.Anything).Return(true)
|
||||
mPort.On("SetStatus", mock.AnythingOfType("uint16"), false).Return(nil)
|
||||
mRegistry.On("Register", mock.Anything, mock.Anything).Return(false)
|
||||
err := s.HandleTCPForward(getReq(t, cConn, sReqs), "localhost", 0)
|
||||
err := s.HandleTCPForward(getReq(t, cConn, sReqs), "localhost", 0, false)
|
||||
if err == nil {
|
||||
t.Error("expected error, got nil")
|
||||
} else if !strings.Contains(err.Error(), "Failed to register") {
|
||||
t.Errorf("expected error to contain %q, got %q", "Failed to register", err.Error())
|
||||
}
|
||||
mPort.AssertExpectations(t)
|
||||
})
|
||||
|
||||
t.Run("Finalize fail (Reply fail)", func(t *testing.T) {
|
||||
s, mRegistry, mPort, _, sReqs, cConn, cleanup := setup(t)
|
||||
s, mRegistry, mPort, sConn, sReqs, cConn, cleanup := setup(t)
|
||||
defer cleanup()
|
||||
mPort.On("Claim", mock.Anything).Return(true)
|
||||
mPort.On("SetStatus", mock.AnythingOfType("uint16"), false).Return(nil)
|
||||
mRegistry.On("Register", mock.Anything, mock.Anything).Return(true)
|
||||
req := getReq(t, cConn, sReqs)
|
||||
err := cConn.Close()
|
||||
assert.NoError(t, err)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
_ = sConn.Wait()
|
||||
|
||||
err = s.HandleTCPForward(req, "localhost", 0)
|
||||
err = s.HandleTCPForward(req, "localhost", 0, false)
|
||||
if err == nil {
|
||||
t.Error("expected error, got nil")
|
||||
} else if !strings.Contains(err.Error(), "Failed to finalize forwarding") {
|
||||
t.Errorf("expected error to contain %q, got %q", "Failed to finalize forwarding", err.Error())
|
||||
}
|
||||
mPort.AssertExpectations(t)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package slug
|
||||
|
||||
import "sync"
|
||||
|
||||
type Slug interface {
|
||||
String() string
|
||||
Set(slug string)
|
||||
}
|
||||
|
||||
type slug struct {
|
||||
mu sync.RWMutex
|
||||
slug string
|
||||
}
|
||||
|
||||
@@ -16,9 +19,13 @@ func New() Slug {
|
||||
}
|
||||
|
||||
func (s *slug) String() string {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.slug
|
||||
}
|
||||
|
||||
func (s *slug) Set(slug string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.slug = slug
|
||||
}
|
||||
@@ -55,8 +55,7 @@ func TestHTTPServer_Serve(t *testing.T) {
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
_ = listener.Close()
|
||||
}()
|
||||
|
||||
err = srv.Serve(listener)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
@@ -16,7 +17,7 @@ import (
|
||||
"tunnel_pls/internal/http/stream"
|
||||
"tunnel_pls/internal/middleware"
|
||||
"tunnel_pls/internal/registry"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
@@ -52,25 +53,43 @@ func (hh *httpHandler) badRequest(conn net.Conn) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func readHTTPHeader(br *bufio.Reader, limit int) ([]byte, error) {
|
||||
var headerBuf []byte
|
||||
for {
|
||||
line, err := br.ReadSlice('\n')
|
||||
headerBuf = append(headerBuf, line...)
|
||||
if errors.Is(err, bufio.ErrBufferFull) {
|
||||
if len(headerBuf) > limit {
|
||||
return nil, fmt.Errorf("headers too large")
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if bytes.HasSuffix(headerBuf, []byte("\r\n\r\n")) {
|
||||
return headerBuf, nil
|
||||
}
|
||||
if len(headerBuf) > limit {
|
||||
return nil, fmt.Errorf("headers too large")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (hh *httpHandler) Handler(conn net.Conn, isTLS bool) {
|
||||
defer hh.closeConnection(conn)
|
||||
|
||||
_ = conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||
buf := make([]byte, hh.config.HeaderSize())
|
||||
n, err := conn.Read(buf)
|
||||
br := bufio.NewReaderSize(conn, hh.config.HeaderSize())
|
||||
headerBuf, err := readHTTPHeader(br, hh.config.HeaderSize())
|
||||
if err != nil {
|
||||
_ = hh.badRequest(conn)
|
||||
return
|
||||
}
|
||||
|
||||
if idx := bytes.Index(buf[:n], []byte("\r\n\r\n")); idx == -1 {
|
||||
_ = hh.badRequest(conn)
|
||||
return
|
||||
}
|
||||
|
||||
_ = conn.SetReadDeadline(time.Time{})
|
||||
|
||||
reqhf, err := header.NewRequest(buf[:n])
|
||||
reqhf, err := header.NewRequest(headerBuf)
|
||||
if err != nil {
|
||||
log.Printf("Error creating request header: %v", err)
|
||||
_ = hh.badRequest(conn)
|
||||
@@ -97,11 +116,11 @@ func (hh *httpHandler) Handler(conn net.Conn, isTLS bool) {
|
||||
Type: types.TunnelTypeHTTP,
|
||||
})
|
||||
if err != nil {
|
||||
_ = hh.redirect(conn, http.StatusMovedPermanently, fmt.Sprintf("https://tunel.live/tunnel-not-found?slug=%s\r\n", slug))
|
||||
_ = hh.redirect(conn, http.StatusMovedPermanently, fmt.Sprintf("https://tunnl.live/tunnel-not-found?slug=%s\r\n", slug))
|
||||
return
|
||||
}
|
||||
|
||||
hw := stream.New(conn, conn, conn.RemoteAddr())
|
||||
hw := stream.New(conn, br, conn.RemoteAddr())
|
||||
defer func(hw stream.HTTP) {
|
||||
err = hw.Close()
|
||||
if err != nil {
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
"tunnel_pls/internal/registry"
|
||||
"tunnel_pls/session/forwarder"
|
||||
"tunnel_pls/session/interaction"
|
||||
"tunnel_pls/session/lifecycle"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/session/forwarder"
|
||||
"tunnel_pls/internal/session/interaction"
|
||||
"tunnel_pls/internal/session/lifecycle"
|
||||
"tunnel_pls/internal/session/slug"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
|
||||
@@ -290,7 +290,7 @@ func TestHandler(t *testing.T) {
|
||||
isTLS: true,
|
||||
redirectTLS: false,
|
||||
request: []byte("GET / HTTP/1.1\r\nHost: test.domain\r\n\r\n"),
|
||||
expected: []byte("HTTP/1.1 301 Moved Permanently\r\nLocation: https://tunel.live/tunnel-not-found?slug=test\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"),
|
||||
expected: []byte("HTTP/1.1 301 Moved Permanently\r\nLocation: https://tunnl.live/tunnel-not-found?slug=test\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"),
|
||||
setupMocks: func(msr *MockSessionRegistry) {
|
||||
msr.On("Get", types.SessionKey{
|
||||
Id: "test",
|
||||
@@ -321,8 +321,14 @@ func TestHandler(t *testing.T) {
|
||||
isTLS: false,
|
||||
redirectTLS: false,
|
||||
request: []byte(""),
|
||||
expected: []byte("HTTP/1.1 400 Bad Request\r\n\r\n"),
|
||||
setupMocks: func(msr *MockSessionRegistry) {
|
||||
expected: []byte(""),
|
||||
setupConn: func() (net.Conn, net.Conn) {
|
||||
mc := new(MockConn)
|
||||
mc.ReadBuffer = bytes.NewBuffer(nil)
|
||||
mc.On("SetReadDeadline", mock.Anything).Return(nil)
|
||||
mc.On("Write", []byte("HTTP/1.1 400 Bad Request\r\n\r\n")).Return(0, nil)
|
||||
mc.On("Close").Return(nil)
|
||||
return mc, nil
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -715,3 +721,113 @@ func TestHandler(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlerForwardsPostBody(t *testing.T) {
|
||||
mockSessionRegistry := new(MockSessionRegistry)
|
||||
mockConfig := &MockConfig{}
|
||||
mockConfig.On("Domain").Return("example.com")
|
||||
mockConfig.On("HTTPPort").Return("0")
|
||||
mockConfig.On("HeaderSize").Return(4096)
|
||||
mockConfig.On("TLSRedirect").Return(true)
|
||||
hh := &httpHandler{
|
||||
sessionRegistry: mockSessionRegistry,
|
||||
config: mockConfig,
|
||||
}
|
||||
|
||||
mockSession := new(MockSession)
|
||||
mockForwarder := new(MockForwarder)
|
||||
mockSSHChannel := new(MockSSHChannel)
|
||||
|
||||
mockSessionRegistry.On("Get", types.SessionKey{
|
||||
Id: "test",
|
||||
Type: types.TunnelTypeHTTP,
|
||||
}).Return(mockSession, nil)
|
||||
mockSession.On("Forwarder").Return(mockForwarder)
|
||||
|
||||
reqCh := make(chan *ssh.Request)
|
||||
mockForwarder.On("OpenForwardedChannel", mock.Anything, mock.Anything).Return(mockSSHChannel, (<-chan *ssh.Request)(reqCh), nil)
|
||||
|
||||
var mu sync.Mutex
|
||||
var capturedHeaders []byte
|
||||
mockSSHChannel.On("Write", mock.Anything).Run(func(args mock.Arguments) {
|
||||
mu.Lock()
|
||||
capturedHeaders = append(capturedHeaders, args.Get(0).([]byte)...)
|
||||
mu.Unlock()
|
||||
}).Return(0, nil)
|
||||
mockSSHChannel.On("Close").Return(nil)
|
||||
|
||||
bodyChan := make(chan string, 1)
|
||||
mockForwarder.On("HandleConnection", mock.Anything, mockSSHChannel).Run(func(args mock.Arguments) {
|
||||
w := args.Get(0).(io.ReadWriter)
|
||||
buf := make([]byte, len("hello=world"))
|
||||
if _, err := io.ReadFull(w, buf); err != nil {
|
||||
bodyChan <- ""
|
||||
} else {
|
||||
bodyChan <- string(buf)
|
||||
}
|
||||
_, _ = w.Write([]byte("HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nok"))
|
||||
})
|
||||
|
||||
go func() {
|
||||
for range reqCh {
|
||||
}
|
||||
}()
|
||||
|
||||
serverConn, clientConn := net.Pipe()
|
||||
defer func() {
|
||||
_ = clientConn.Close()
|
||||
}()
|
||||
|
||||
remoteAddr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:12345")
|
||||
wrappedServerConn := &wrappedConn{Conn: serverConn, remoteAddr: remoteAddr}
|
||||
|
||||
go hh.Handler(wrappedServerConn, true)
|
||||
|
||||
request := []byte("POST / HTTP/1.1\r\nHost: test.domain\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 11\r\n\r\nhello=world")
|
||||
go func() {
|
||||
_, _ = clientConn.Write(request)
|
||||
}()
|
||||
|
||||
var response []byte
|
||||
respDone := make(chan struct{})
|
||||
go func() {
|
||||
defer close(respDone)
|
||||
buf := make([]byte, 4096)
|
||||
for {
|
||||
n, err := clientConn.Read(buf)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
response = append(response, buf[:n]...)
|
||||
if bytes.Contains(response, []byte("\r\n\r\nok")) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case body := <-bodyChan:
|
||||
assert.Equal(t, "hello=world", body)
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("timed out waiting for forwarded body")
|
||||
}
|
||||
|
||||
select {
|
||||
case <-respDone:
|
||||
resStr := string(response)
|
||||
assert.True(t, strings.HasPrefix(resStr, "HTTP/1.1 200 OK\r\n"))
|
||||
assert.Contains(t, resStr, "Server: Tunnel Please\r\n")
|
||||
assert.True(t, strings.HasSuffix(resStr, "\r\n\r\nok"))
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("timed out waiting for response")
|
||||
}
|
||||
|
||||
mu.Lock()
|
||||
hdrStr := string(capturedHeaders)
|
||||
mu.Unlock()
|
||||
assert.Contains(t, hdrStr, "POST / HTTP/1.1\r\n")
|
||||
assert.Contains(t, hdrStr, "Content-Length: 11\r\n")
|
||||
assert.Contains(t, hdrStr, "X-Forwarded-For: 127.0.0.1\r\n")
|
||||
|
||||
mockSessionRegistry.AssertExpectations(t)
|
||||
}
|
||||
|
||||
@@ -63,8 +63,7 @@ func TestHTTPSServer_Serve(t *testing.T) {
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
_ = listener.Close()
|
||||
}()
|
||||
|
||||
err = srv.Serve(listener)
|
||||
|
||||
@@ -45,8 +45,7 @@ func TestTCPServer_Serve(t *testing.T) {
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
_ = listener.Close()
|
||||
}()
|
||||
|
||||
err = srv.Serve(listener)
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
"tunnel_pls/internal/config"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/internal/types"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
+2
-3
@@ -11,9 +11,8 @@
|
||||
"digest"
|
||||
],
|
||||
"automerge": true,
|
||||
"groupName": "all-dependencies",
|
||||
"matchPackageNames": [
|
||||
"*"
|
||||
"baseBranchPatterns": [
|
||||
"staging"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user