Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ai3
accountserver
Commits
66a3e2d6
Commit
66a3e2d6
authored
Dec 05, 2021
by
ale
Browse files
Fix availability checks for some missed list/newsletter cases
Add tests for that too.
parent
a319c94b
Pipeline
#24839
passed with stages
in 3 minutes and 50 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
actions_resource.go
View file @
66a3e2d6
package
accountserver
package
accountserver
import
(
import
(
"errors"
"fmt"
"fmt"
"log"
"log"
)
)
...
@@ -196,7 +195,7 @@ func (r *CheckResourceAvailabilityRequest) Validate(rctx *RequestContext) error
...
@@ -196,7 +195,7 @@ func (r *CheckResourceAvailabilityRequest) Validate(rctx *RequestContext) error
func
(
r
*
CheckResourceAvailabilityRequest
)
Serve
(
rctx
*
RequestContext
)
(
interface
{},
error
)
{
func
(
r
*
CheckResourceAvailabilityRequest
)
Serve
(
rctx
*
RequestContext
)
(
interface
{},
error
)
{
var
check
ValidatorFunc
var
check
ValidatorFunc
switch
r
.
Type
{
switch
r
.
Type
{
case
ResourceTypeEmail
,
ResourceTypeMailingList
:
case
ResourceTypeEmail
,
ResourceTypeMailingList
,
ResourceTypeNewsletter
:
check
=
rctx
.
validationCtx
.
isAvailableEmailAddr
()
check
=
rctx
.
validationCtx
.
isAvailableEmailAddr
()
case
ResourceTypeDomain
:
case
ResourceTypeDomain
:
check
=
rctx
.
validationCtx
.
isAvailableDomain
()
check
=
rctx
.
validationCtx
.
isAvailableDomain
()
...
@@ -207,7 +206,7 @@ func (r *CheckResourceAvailabilityRequest) Serve(rctx *RequestContext) (interfac
...
@@ -207,7 +206,7 @@ func (r *CheckResourceAvailabilityRequest) Serve(rctx *RequestContext) (interfac
case
ResourceTypeDatabase
:
case
ResourceTypeDatabase
:
check
=
rctx
.
validationCtx
.
isAvailableDatabase
()
check
=
rctx
.
validationCtx
.
isAvailableDatabase
()
default
:
default
:
return
nil
,
errors
.
New
(
"unknown resource type"
)
return
nil
,
newValidationError
(
nil
,
"type"
,
"unknown resource type"
)
}
}
var
resp
CheckResourceAvailabilityResponse
var
resp
CheckResourceAvailabilityResponse
...
...
backend/ldap/resources.go
View file @
66a3e2d6
...
@@ -100,7 +100,8 @@ func setCommonResourceAttrs(entry *ldap.Entry, rsrc *as.Resource) {
...
@@ -100,7 +100,8 @@ func setCommonResourceAttrs(entry *ldap.Entry, rsrc *as.Resource) {
func
(
reg
*
resourceRegistry
)
FromLDAP
(
entry
*
ldap
.
Entry
)
(
rsrc
*
as
.
Resource
,
err
error
)
{
func
(
reg
*
resourceRegistry
)
FromLDAP
(
entry
*
ldap
.
Entry
)
(
rsrc
*
as
.
Resource
,
err
error
)
{
// Since we don't know what resource type to expect, we try
// Since we don't know what resource type to expect, we try
// all known handlers until one returns a valid Resource.
// all known handlers until one returns a valid Resource.
// This is slightly dangerous unless all
// This expects that all object types can be told apart by
// their DN or attributes.
for
_
,
h
:=
range
reg
.
handlers
{
for
_
,
h
:=
range
reg
.
handlers
{
rsrc
,
err
=
h
.
FromLDAP
(
entry
)
rsrc
,
err
=
h
.
FromLDAP
(
entry
)
if
err
==
nil
{
if
err
==
nil
{
...
...
integrationtest/availability_test.go
0 → 100644
View file @
66a3e2d6
package
integrationtest
import
(
"testing"
as
"git.autistici.org/ai3/accountserver"
)
func
TestIntegration_CheckResourceAvailability
(
t
*
testing
.
T
)
{
stop
,
_
,
c
:=
startService
(
t
)
defer
stop
()
testdata
:=
[]
struct
{
rtype
string
name
string
expectedAvail
bool
}{
{
"email"
,
"uno@investici.org"
,
false
},
{
"email"
,
"due@investici.org"
,
false
},
{
"email"
,
"tre@investici.org"
,
false
},
{
"email"
,
"newsletter1@investici.org"
,
false
},
{
"email"
,
"list4@investici.org"
,
false
},
{
"email"
,
"new@investici.org"
,
true
},
{
"list"
,
"newsletter1@investici.org"
,
false
},
{
"list"
,
"list4@investici.org"
,
false
},
{
"newsletter"
,
"newsletter1@investici.org"
,
false
},
{
"newsletter"
,
"list4@investici.org"
,
false
},
{
"web"
,
"due"
,
false
},
{
"web"
,
"new"
,
true
},
{
"dav"
,
"uno"
,
false
},
{
"dav"
,
"new"
,
true
},
}
for
_
,
td
:=
range
testdata
{
var
resp
as
.
CheckResourceAvailabilityResponse
err
:=
c
.
request
(
"/api/resource/check_availability"
,
&
as
.
CheckResourceAvailabilityRequest
{
Type
:
td
.
rtype
,
Name
:
td
.
name
,
},
&
resp
)
if
err
!=
nil
{
t
.
Errorf
(
"CheckResourceAvailability(%s/%s) error: %v"
,
td
.
rtype
,
td
.
name
,
err
)
continue
}
if
resp
.
Available
!=
td
.
expectedAvail
{
t
.
Errorf
(
"CheckResourceAvailability(%s/%s) returned %v, expected %v"
,
td
.
rtype
,
td
.
name
,
resp
.
Available
,
td
.
expectedAvail
)
}
}
}
integrationtest/testdata/test4.ldif
View file @
66a3e2d6
...
@@ -41,3 +41,14 @@ status: active
...
@@ -41,3 +41,14 @@ status: active
uidNumber: 23801
uidNumber: 23801
userPassword:: JGEyJDQkMzI3NjgkMSQwZDgyMzU1YjQ0Mzg0M2NmZDY4MjU1MzE4ZTVjYTdiZSRmNTQ0ODkxOTFiNWZlYzk2MDRlNWQ2ODZjMDQxZjJkNTFmOTgxOGY4ZTFmM2E4MDYzY2U3ZTEwMTE3OTc2OGI0
userPassword:: JGEyJDQkMzI3NjgkMSQwZDgyMzU1YjQ0Mzg0M2NmZDY4MjU1MzE4ZTVjYTdiZSRmNTQ0ODkxOTFiNWZlYzk2MDRlNWQ2ODZjMDQxZjJkNTFmOTgxOGY4ZTFmM2E4MDYzY2U3ZTEwMTE3OTc2OGI0
dn: listName=list4@investici.org,ou=Lists,dc=example,dc=com
objectClass: mailingList
objectClass: top
listName: list4@investici.org
listDescription: Mailing list 4
public: no
status: active
listOwner: quattro@investici.org
host: host2
originalHost: host2
server/server.go
View file @
66a3e2d6
...
@@ -251,6 +251,8 @@ func errToStatus(err error) int {
...
@@ -251,6 +251,8 @@ func errToStatus(err error) int {
return
http
.
StatusForbidden
return
http
.
StatusForbidden
case
as
.
IsRequestError
(
err
)
:
case
as
.
IsRequestError
(
err
)
:
return
http
.
StatusBadRequest
return
http
.
StatusBadRequest
case
as
.
IsValidationError
(
err
)
:
return
http
.
StatusBadRequest
default
:
default
:
return
http
.
StatusInternalServerError
return
http
.
StatusInternalServerError
}
}
...
...
validators.go
View file @
66a3e2d6
...
@@ -349,14 +349,18 @@ func splitEmailAddr(addr string) (string, string) {
...
@@ -349,14 +349,18 @@ func splitEmailAddr(addr string) (string, string) {
// Returns all the possible resources in the email and mailing list
// Returns all the possible resources in the email and mailing list
// namespaces that might conflict with the given email address.
// namespaces that might conflict with the given email address.
func
relatedEmails
(
ctx
context
.
Context
,
be
domainBackend
,
addr
string
)
[]
FindResourceRequest
{
func
relatedEmails
(
ctx
context
.
Context
,
be
domainBackend
,
addr
string
)
[]
FindResourceRequest
{
// Check for the literal addr in the unified mail+list namespace.
rel
:=
[]
FindResourceRequest
{
rel
:=
[]
FindResourceRequest
{
{
Type
:
ResourceTypeEmail
,
Name
:
addr
},
{
Type
:
ResourceTypeEmail
,
Name
:
addr
},
{
Type
:
ResourceTypeMailingList
,
Name
:
addr
},
{
Type
:
ResourceTypeNewsletter
,
Name
:
addr
},
}
}
user
,
_
:=
splitEmailAddr
(
addr
)
// Mailing lists and newsletters must have unique names
// Mailing lists and newsletters must have unique names
// regardless of the domain, so we add potential conflicts for
// regardless of the domain, so we add potential conflicts for
// mailing lists with the same name over all list-enabled
// mailing lists with the same name over all list-enabled
// domains.
// domains.
user
,
_
:=
splitEmailAddr
(
addr
)
for
_
,
d
:=
range
be
.
GetAllowedDomains
(
ctx
,
ResourceTypeMailingList
)
{
for
_
,
d
:=
range
be
.
GetAllowedDomains
(
ctx
,
ResourceTypeMailingList
)
{
rel
=
append
(
rel
,
FindResourceRequest
{
rel
=
append
(
rel
,
FindResourceRequest
{
Type
:
ResourceTypeMailingList
,
Type
:
ResourceTypeMailingList
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment