|
| 1 | +// This file is part of arduino-app-cli. |
| 2 | +// |
| 3 | +// Copyright 2025 ARDUINO SA (http://www.arduino.cc/) |
| 4 | +// |
| 5 | +// This software is released under the GNU General Public License version 3, |
| 6 | +// which covers the main part of arduino-app-cli. |
| 7 | +// The terms of this license can be found at: |
| 8 | +// https://www.gnu.org/licenses/gpl-3.0.en.html |
| 9 | +// |
| 10 | +// You can be released from the requirements of the above licenses by purchasing |
| 11 | +// a commercial license. Buying such a license is mandatory if you want to |
| 12 | +// modify or otherwise use the software for commercial activities involving the |
| 13 | +// Arduino software without disclosing the source code of your own applications. |
| 14 | +// To purchase a commercial license, send an email to license@arduino.cc. |
| 15 | + |
| 16 | +package handlers |
| 17 | + |
| 18 | +import ( |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/stretchr/testify/require" |
| 22 | +) |
| 23 | + |
| 24 | +func TestCheckOrigin(t *testing.T) { |
| 25 | + origins := []string{ |
| 26 | + "wails://wails", |
| 27 | + "wails://wails.localhost:*", |
| 28 | + "http://wails.localhost:*", |
| 29 | + "http://localhost:*", |
| 30 | + "https://localhost:*", |
| 31 | + "http://example.com:7000", |
| 32 | + "https://*:443", |
| 33 | + } |
| 34 | + |
| 35 | + allow := func(origin string) { |
| 36 | + require.True(t, checkOrigin(origin, origins), "Expected origin %s to be allowed", origin) |
| 37 | + } |
| 38 | + deny := func(origin string) { |
| 39 | + require.False(t, checkOrigin(origin, origins), "Expected origin %s to be denied", origin) |
| 40 | + } |
| 41 | + allow("wails://wails") |
| 42 | + allow("wails://wails:8000") |
| 43 | + allow("http://wails.localhost") |
| 44 | + allow("http://example.com:7000") |
| 45 | + allow("https://blah.com:443") |
| 46 | + deny("wails://evil.com") |
| 47 | + deny("https://wails.localhost:8000") |
| 48 | + deny("http://example.com:8000") |
| 49 | + deny("http://blah.com:443") |
| 50 | + deny("https://blah.com:8080") |
| 51 | +} |
0 commit comments