File: mfa_test.go

package info (click to toggle)
golang-github-denverdino-aliyungo 0.0~git20180921.13fa8aa-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,824 kB
  • sloc: xml: 1,359; makefile: 3
file content (84 lines) | stat: -rw-r--r-- 2,325 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package ram

import (
	"strconv"
	"testing"
	"time"
)

var (
	uname               string
	serialNumber        string
	mFADeviceName       = strconv.FormatInt(time.Now().Unix(), 10)
	mFARequest          = MFARequest{VirtualMFADeviceName: mFADeviceName}
	authenticationCode1 = "Hello" //depends on your device
	authenticationCode2 = "World" //depends on your device
)

func TestCreateVirtualMFADevice(t *testing.T) {
	client := NewTestClient()
	resp, err := client.CreateVirtualMFADevice(mFARequest)
	if err != nil {
		t.Errorf("Failed to CreateVirtualMFADevice %v", err)
	}
	serialNumber = resp.VirtualMFADevice.SerialNumber
	t.Logf("pass CreateVirtualMFADevice %v", resp)
}

func TestListVirtualMFADevices(t *testing.T) {
	client := NewTestClient()
	resp, err := client.ListVirtualMFADevices()
	if err != nil {
		t.Errorf("Failed to ListVirtualMFADevices %v", err)
	}
	t.Logf("pass ListVirtualMFADevices %v", resp)
}

func TestBindMFADevice(t *testing.T) {
	client := NewTestClient()
	listParams := ListUserRequest{}
	resp, err := client.ListUsers(listParams)
	if err != nil {
		t.Errorf("Failed to ListUser %v", err)
		return
	}
	uname = resp.Users.User[0].UserName
	req := MFABindRequest{
		SerialNumber:        serialNumber,
		UserName:            uname,
		AuthenticationCode1: authenticationCode1,
		AuthenticationCode2: authenticationCode2,
	}
	response, err := client.BindMFADevice(req)
	if err != nil {
		t.Errorf("Failed to BindMFADevice %v", err)
	}
	t.Logf("pass BindMFADevice %v", response)
}

func TestGetUserMFAInfo(t *testing.T) {
	client := NewTestClient()
	resp, err := client.GetUserMFAInfo(UserQueryRequest{UserName: uname})
	if err != nil {
		t.Errorf("Failed to GetUserMFAInfo %v", err)
	}
	t.Logf("pass GetUserMFAInfo %v", resp)
}

func TestUnbindMFADevice(t *testing.T) {
	client := NewTestClient()
	response, err := client.UnbindMFADevice(UserQueryRequest{UserName: uname})
	if err != nil {
		t.Errorf("Failed to UnbindMFADevice %v", err)
	}
	t.Logf("pass UnbindMFADevice %v", response)
}

func TestDeleteVirtualMFADevice(t *testing.T) {
	client := NewTestClient()
	resp, err := client.DeleteVirtualMFADevice(MFADeleteRequest{MFADevice: MFADevice{SerialNumber: serialNumber}})
	if err != nil {
		t.Errorf("Failed to DeleteVirtualMFADevice %v", err)
	}
	t.Logf("pass DeleteVirtualMFADevice %v", resp)
}