ultisuite-backend/internal/nextcloud/users_test.go
R3D347HR4Y 556d5f416d Enhance API and configuration for contact discovery and public sharing
- Introduced new endpoints for contact discovery, including scanning, listing, and managing discovered contacts.
- Implemented retry logic for handling missing DAV credentials during contact operations.
- Added public share functionality for drive API, allowing users to manage public shares, including upload, delete, and rename operations.
- Updated Nextcloud configuration to support public share links and improved error handling for public share permissions.
- Enhanced logging and validation across contact and drive APIs for better error tracking and user feedback.
- Added tests for new contact matching and ranking functionalities to ensure accuracy and reliability.
2026-06-06 20:27:02 +02:00

60 lines
1.5 KiB
Go

package nextcloud
import "testing"
func TestUserIDFromClaimsPrefersEmail(t *testing.T) {
got := UserIDFromClaims("User@Example.com", "opaque-sub")
if got != "user@example.com" {
t.Fatalf("UserIDFromClaims() = %q", got)
}
}
func TestUserIDFromClaimsFallbackSub(t *testing.T) {
got := UserIDFromClaims("", "opaque-sub")
if got != "opaque-sub" {
t.Fatalf("UserIDFromClaims() = %q", got)
}
}
func TestNormalizeDAVHref(t *testing.T) {
tests := []struct {
in, want string
}{
{
"/cloud/remote.php/dav/addressbooks/users/alice/contacts/",
"/remote.php/dav/addressbooks/users/alice/contacts/",
},
{
"cloud/remote.php/dav/addressbooks/users/alice/contacts/uid.vcf",
"/remote.php/dav/addressbooks/users/alice/contacts/uid.vcf",
},
{
"/remote.php/dav/addressbooks/users/alice/contacts/uid.vcf",
"/remote.php/dav/addressbooks/users/alice/contacts/uid.vcf",
},
}
for _, tc := range tests {
got := normalizeDAVHref(tc.in)
if got != tc.want {
t.Fatalf("normalizeDAVHref(%q) = %q, want %q", tc.in, got, tc.want)
}
}
}
func TestDavResponseErrorNotFound(t *testing.T) {
raw := []byte(`<?xml version="1.0"?><d:error xmlns:d="DAV:"><d:message>missing</d:message></d:error>`)
if err := davResponseError(raw, 404); err != ErrPrincipalNotFound {
t.Fatalf("davResponseError() = %v", err)
}
}
func TestGenerateNextcloudPassword(t *testing.T) {
pw, err := generateNextcloudPassword()
if err != nil {
t.Fatal(err)
}
if len(pw) < 24 {
t.Fatalf("password too short: %d", len(pw))
}
}