mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
testing duplicate handles
This commit is contained in:
parent
cb71ff8b94
commit
860d0fd5a6
@ -75,8 +75,53 @@ func TestAccount(t *testing.T) {
|
|||||||
dec = json.NewDecoder(resp.Body)
|
dec = json.NewDecoder(resp.Body)
|
||||||
var profile Profile
|
var profile Profile
|
||||||
dec.Decode(&profile)
|
dec.Decode(&profile)
|
||||||
if profile.Guid == "" {
|
if profile.Handle != "user" {
|
||||||
t.Errorf("invalid profile")
|
t.Errorf("invalid profile")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// acquire new token for creating accounts
|
||||||
|
auth = base64.StdEncoding.EncodeToString([]byte("admin:pass"))
|
||||||
|
r = httptest.NewRequest("POST", "/admin/accounts", nil)
|
||||||
|
r.Header.Add("Authorization","Basic " + auth)
|
||||||
|
w = httptest.NewRecorder()
|
||||||
|
AddNodeAccount(w, r)
|
||||||
|
resp = w.Result()
|
||||||
|
dec = json.NewDecoder(resp.Body)
|
||||||
|
dec.Decode(&token)
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
t.Errorf("failed to create account")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if username is available
|
||||||
|
r = httptest.NewRequest("GET", "/account/claimable?username=user", nil)
|
||||||
|
r.Header.Add("Authorization","Bearer " + token)
|
||||||
|
w = httptest.NewRecorder()
|
||||||
|
GetAccountUsername(w, r)
|
||||||
|
resp = w.Result()
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
t.Errorf("invalid token value")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dec = json.NewDecoder(resp.Body)
|
||||||
|
dec.Decode(&available)
|
||||||
|
if available {
|
||||||
|
t.Errorf("username duplicate available")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// create account
|
||||||
|
auth = base64.StdEncoding.EncodeToString([]byte("user:pass"))
|
||||||
|
r = httptest.NewRequest("GET", "/account/profile", nil)
|
||||||
|
r.Header.Add("Credentials","Basic " + auth)
|
||||||
|
r.Header.Add("Authorization","Bearer " + token)
|
||||||
|
w = httptest.NewRecorder()
|
||||||
|
AddAccount(w, r)
|
||||||
|
resp = w.Result()
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
t.Errorf("duplicate handle set")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ type Account struct {
|
|||||||
DialogueRevision int64 `gorm:"not null;default:1"`
|
DialogueRevision int64 `gorm:"not null;default:1"`
|
||||||
InsightRevision uint64 `gorm:"not null;default:1"`
|
InsightRevision uint64 `gorm:"not null;default:1"`
|
||||||
Created int64 `gorm:"autoCreateTime"`
|
Created int64 `gorm:"autoCreateTime"`
|
||||||
|
Disabled bool `gorm:"not null;default:false"`
|
||||||
Apps []App
|
Apps []App
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user