mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-02 02:11:18 -06:00
The old approach of the authentication middlewares had the problem that when an authenticator could not authenticate a request it would still send it to the next handler, in case that the next one can authenticate it. But if no authenticator could successfully authenticate the request, it would still be handled, which leads to unauthorized access.
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package middleware
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
/**/
|
|
|
|
func TestBasicAuth__isPublicLink(t *testing.T) {
|
|
tests := []struct {
|
|
url string
|
|
username string
|
|
expected bool
|
|
}{
|
|
{url: "/remote.php/dav/public-files/", username: "", expected: false},
|
|
{url: "/remote.php/dav/public-files/", username: "abc", expected: false},
|
|
{url: "/remote.php/dav/public-files/", username: "private", expected: false},
|
|
{url: "/remote.php/dav/public-files/", username: "public", expected: true},
|
|
{url: "/ocs/v1.php/cloud/capabilities", username: "", expected: false},
|
|
{url: "/ocs/v1.php/cloud/capabilities", username: "abc", expected: false},
|
|
{url: "/ocs/v1.php/cloud/capabilities", username: "private", expected: false},
|
|
{url: "/ocs/v1.php/cloud/capabilities", username: "public", expected: true},
|
|
{url: "/ocs/v1.php/cloud/users/admin", username: "public", expected: false},
|
|
}
|
|
for _, tt := range tests {
|
|
req := httptest.NewRequest("", tt.url, nil)
|
|
|
|
if tt.username != "" {
|
|
req.SetBasicAuth(tt.username, "")
|
|
}
|
|
|
|
result := isPublicPath(req.URL.Path)
|
|
if result != tt.expected {
|
|
t.Errorf("with %s expected %t got %t", tt.url, tt.expected, result)
|
|
}
|
|
}
|
|
}
|