-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
111 lines (96 loc) · 5.17 KB
/
main_test.go
File metadata and controls
111 lines (96 loc) · 5.17 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package main
import (
"strings"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
var testPassword = "p@55w0rd"
var testToken = "t0k3n"
var testSecret = "s3cr3t"
func TestObfuscate(t *testing.T) {
patternsToObfuscate = append(patternsToObfuscate, testPassword)
patternsToObfuscate = append(patternsToObfuscate, testToken)
patternsToObfuscate = append(patternsToObfuscate, testSecret)
Convey("Given an input for fsm", t, func() {
fsmMessage := `{"id":"1","datacenters":{"items":[{"name":"test","username":"test","password":"p@55w0rd"}]}}`
Convey("the message should be processed correctly and its password removed", func() {
message := Obfuscate("x", fsmMessage)
So(strings.Contains(message, testPassword), ShouldBeFalse)
So(strings.Contains(message, "test"), ShouldBeTrue)
So(strings.Contains(message, "1"), ShouldBeTrue)
})
})
Convey("Given an input for routers creation", t, func() {
routerMessage := `{"service":"1","components":[{"datacenter_name":"test","datacenter_password":"p@55w0rd"}]}`
Convey("the message should be processed correctly and its password removed", func() {
message := Obfuscate("x", routerMessage)
So(strings.Contains(message, testPassword), ShouldBeFalse)
So(strings.Contains(message, "test"), ShouldBeTrue)
So(strings.Contains(message, "1"), ShouldBeTrue)
})
})
Convey("Given an input for networks creation", t, func() {
networkMessage := `{"service":"1","components":[{"datacenter_name":"test","datacenter_password":"p@55w0rd"}]}`
Convey("the message should be processed correctly and its password removed", func() {
message := Obfuscate("x", networkMessage)
So(strings.Contains(message, testPassword), ShouldBeFalse)
So(strings.Contains(message, "test"), ShouldBeTrue)
So(strings.Contains(message, "1"), ShouldBeTrue)
})
})
Convey("Given an input for instances creation", t, func() {
instanceMessage := `{"service":"1","components":[{"datacenter_name":"test","datacenter_password":"p@55w0rd"}]}`
Convey("the message should be processed correctly and its password removed", func() {
message := Obfuscate("x", instanceMessage)
So(strings.Contains(message, testPassword), ShouldBeFalse)
So(strings.Contains(message, "test"), ShouldBeTrue)
So(strings.Contains(message, "1"), ShouldBeTrue)
})
})
Convey("Given an input for firewalls creation", t, func() {
firewallMessage := `{"service":"1","components":[{"datacenter_name":"test","datacenter_password":"p@55w0rd"}]}`
Convey("the message should be processed correctly and its password removed", func() {
message := Obfuscate("x", firewallMessage)
So(strings.Contains(message, testPassword), ShouldBeFalse)
So(strings.Contains(message, "test"), ShouldBeTrue)
So(strings.Contains(message, "1"), ShouldBeTrue)
})
})
Convey("Given an input for nats creation", t, func() {
natMessage := `{"service":"1","components":[{"datacenter_name":"test","datacenter_password":"p@55w0rd"}]}`
Convey("the message should be processed correctly and its password removed", func() {
message := Obfuscate("x", natMessage)
So(strings.Contains(message, testPassword), ShouldBeFalse)
So(strings.Contains(message, "test"), ShouldBeTrue)
So(strings.Contains(message, "1"), ShouldBeTrue)
})
})
Convey("Given an input for singular generic message", t, func() {
executionMessage := `{"service":"1", "datacenter_password": "p@55w0rd"}`
Convey("the message should be processed correctly and its password removed", func() {
message := Obfuscate("x", executionMessage)
So(strings.Contains(message, testPassword), ShouldBeFalse)
So(strings.Contains(message, "1"), ShouldBeTrue)
})
})
Convey("Given an input for getting configuration of a service", t, func() {
configurationMessage := `{"user":"username", "password": "p@55w0rd"}`
Convey("the message should be processed correctly and its password removed", func() {
message := Obfuscate("x", configurationMessage)
So(strings.Contains(message, testPassword), ShouldBeFalse)
So(strings.Contains(message, "username"), ShouldBeTrue)
})
})
Convey("Given an input for a list of datacenters", t, func() {
configurationMessage := `[{"id":4,"group_id":2,"name":"name","type":"aws","region":"eu-west-1","username":"name","password":"","vcloud_url":"","vse_url":"","external_network":"","token":"t0k3n","secret":"s3cr3t","CreatedAt":"2016-11-03T14:32:30.470151Z","UpdatedAt":"2016-11-03T14:32:30.470151Z"},{"id":5,"group_id":2,"name":"name","type":"vcloud","region":"","username":"name@org","password":"p@55w0rd","vcloud_url":"https://myvdc.net","vse_url":"","external_network":"NETWORK","token":"","secret":"","CreatedAt":"2016-11-03T14:32:43.428661Z","UpdatedAt":"2016-11-03T14:32:43.428661Z"}]`
Convey("the message should be processed correctly and its password removed", func() {
message := Obfuscate("x", configurationMessage)
So(strings.Contains(message, testPassword), ShouldBeFalse)
So(strings.Contains(message, testToken), ShouldBeFalse)
So(strings.Contains(message, testSecret), ShouldBeFalse)
})
})
}