Moves the integration tests to be acceptance tests
and examples for identity. partially implements blueprint acceptance-tests Change-Id: I724a45f74d1d929ef571ae25c06443c194615658
This commit is contained in:
parent
7eef44f0c8
commit
c9f5825d62
@ -10,6 +10,8 @@ import (
|
||||
func main() {
|
||||
config := getConfig()
|
||||
|
||||
// Authenticate with just a username and password. The returned token is
|
||||
// unscoped to a tenant.
|
||||
auth, err := identity.AuthUserName(config.Host,
|
||||
config.Username,
|
||||
config.Password)
|
||||
@ -19,4 +21,28 @@ func main() {
|
||||
if !auth.Access.Token.Expires.After(time.Now()) {
|
||||
fmt.Println("There was an error. The auth token has an invalid expiration.")
|
||||
}
|
||||
|
||||
// Authenticate with a username, password, tenant name.
|
||||
auth, err = identity.AuthUserNameTenantName(config.Host,
|
||||
config.Username,
|
||||
config.Password,
|
||||
config.ProjectName)
|
||||
if err != nil {
|
||||
fmt.Println("There was an error authenticating:", err)
|
||||
}
|
||||
if !auth.Access.Token.Expires.After(time.Now()) {
|
||||
fmt.Println("There was an error. The auth token has an invalid expiration.")
|
||||
}
|
||||
|
||||
// Authenticate with a username, password, tenant id.
|
||||
auth, err = identity.AuthUserNameTenantId(config.Host,
|
||||
config.Username,
|
||||
config.Password,
|
||||
config.ProjectID)
|
||||
if err != nil {
|
||||
fmt.Println("There was an error authenticating:", err)
|
||||
}
|
||||
if !auth.Access.Token.Expires.After(time.Now()) {
|
||||
fmt.Println("There was an error. The auth token has an invalid expiration.")
|
||||
}
|
||||
}
|
||||
|
@ -1,101 +0,0 @@
|
||||
//PRE-REQUISITE: Must have valid IdentityService account, either internally
|
||||
//hosted or with one of the OpenStack providers. See identitytest/ for the
|
||||
//JSON specification.
|
||||
//The JSON file ought to be in .hgignore / .gitignore for security reason.
|
||||
package identity_test
|
||||
|
||||
import (
|
||||
"git.openstack.org/stackforge/golang-client.git/identity"
|
||||
"git.openstack.org/stackforge/golang-client.git/identity/identitytest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var account = identitytest.SetupUser("identitytest/user.json")
|
||||
|
||||
func TestAuthKey(t *testing.T) {
|
||||
//Not in OpenStack api doc, but in HPCloud api doc.
|
||||
auth, err := identity.AuthKey(account.Host,
|
||||
account.AccessKey,
|
||||
account.SecretKey)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !auth.Access.Token.Expires.After(time.Now()) {
|
||||
t.Error("expiry is wrong")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthKeyTenantId(t *testing.T) {
|
||||
//Not in OpenStack nor HPCloud api doc, but in HPCloud curl example.
|
||||
auth, err := identity.AuthKeyTenantId(account.Host,
|
||||
account.AccessKey,
|
||||
account.SecretKey,
|
||||
account.TenantId)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !auth.Access.Token.Expires.After(time.Now()) {
|
||||
t.Error("expiry is wrong")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthUserName(t *testing.T) {
|
||||
//Not in OpenStack api doc, but in HPCloud api doc.
|
||||
auth, err := identity.AuthUserName(account.Host,
|
||||
account.UserName,
|
||||
account.Password)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !auth.Access.Token.Expires.After(time.Now()) {
|
||||
t.Error("expiry is wrong")
|
||||
}
|
||||
}
|
||||
func TestAuthUserNameTenantName(t *testing.T) {
|
||||
//In OpenStack api doc, but not in HPCloud api doc, but tested valid in HPCloud.
|
||||
auth, err := identity.AuthUserNameTenantName(account.Host,
|
||||
account.UserName,
|
||||
account.Password,
|
||||
account.TenantName)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !auth.Access.Token.Expires.After(time.Now()) {
|
||||
t.Error("expiry is wrong")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthUserNameTenantId(t *testing.T) {
|
||||
//Not in OpenStack api doc, but in HPCloud api doc.
|
||||
auth, err := identity.AuthUserNameTenantId(account.Host,
|
||||
account.UserName,
|
||||
account.Password,
|
||||
account.TenantId)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !auth.Access.Token.Expires.After(time.Now()) {
|
||||
t.Error("expiry is wrong")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthTenantNameTokenId(t *testing.T) {
|
||||
//Not in OpenStack api doc, but in HPCloud api doc.
|
||||
auth, err := identity.AuthUserNameTenantId(account.Host,
|
||||
account.UserName,
|
||||
account.Password,
|
||||
account.TenantId)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
auth, err = identity.AuthTenantNameTokenId(account.Host,
|
||||
account.TenantName,
|
||||
auth.Access.Token.Id)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !auth.Access.Token.Expires.After(time.Now()) {
|
||||
t.Error("expiry is wrong")
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package identitytest
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
//SetupUser() is used to retrieve externally stored testing credentials.
|
||||
//The testing credentials are stored outside
|
||||
//the source code so they do not get checked in, assuming the user.json is
|
||||
//in .gitignore / .hgignore. "user.json" should contain the following where
|
||||
//... is the actual value from the test user account credentials.
|
||||
//{
|
||||
// "TenantId":"...",
|
||||
// "TenantName": "...",
|
||||
// "AccessKey": "...",
|
||||
// "SecretKey": "...",
|
||||
// "UserName": "...",
|
||||
// "Password": "...",
|
||||
// "Host": "https://.../v2.0/tokens"
|
||||
//}
|
||||
func SetupUser(jsonFile string) (acct struct {
|
||||
TenantId, TenantName, AccessKey, SecretKey, UserName, Password, Host string
|
||||
},) {
|
||||
usrJson, err := ioutil.ReadFile(jsonFile)
|
||||
if err != nil {
|
||||
panic("ReadFile json failed")
|
||||
}
|
||||
if err = json.Unmarshal(usrJson, &acct); err != nil {
|
||||
panic("Unmarshal json failed")
|
||||
}
|
||||
return acct
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user