-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* util: move DecodeAttribute into it's own function, add it to util_test as well, testing the error that broke main branch devices * database settings: move settings over to golang-shared, add basic unmarshal testers * MFW-4883 Fixing unit tests for decode string util function * MFW-4883 Adding interface settings * MFW-4883 Added an extra password attribute * MFW-4883 Fixing database password attr name * MFW-4883 Fixing interfaces settings * Added encrypted password attributed for pppoe * Added attributes for interfaces * MFW-4883 Removing interface structs --------- Co-authored-by: John Sommerville <jsommerville@arista.com> version: bug
- Loading branch information
1 parent
876a74b
commit 4867269
Showing
6 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
services/licensemanager/testdata/appstates/appstate_service_state.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[{"name":"untangle-node-captiveportal","allowedState":0},{"name":"untangle-node-threat-prevention","allowedState":1},{"name":"untangle-node-sitefilter","allowedState":0},{"name":"untangle-node-geoip","allowedState":0},{"name":"untangle-node-discovery","allowedState":0},{"name":"untangle-node-classd","allowedState":1},{"name":"untangle-node-dynamic-lists","allowedState":0}] | ||
[{"name":"untangle-node-discovery","allowedState":0},{"name":"untangle-node-classd","allowedState":1},{"name":"untangle-node-dynamic-lists","allowedState":0},{"name":"untangle-node-captiveportal","allowedState":0},{"name":"untangle-node-threat-prevention","allowedState":1},{"name":"untangle-node-sitefilter","allowedState":0},{"name":"untangle-node-geoip","allowedState":0}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package database_settings | ||
|
||
type Database struct { | ||
Enabled bool `json:"enabled"` | ||
ID string `json:"id"` | ||
Database string `json:"db_name"` | ||
UserName string `json:"db_username"` | ||
Password string `json:"db_password"` | ||
PasswordEncrypted string `json:"db_password_encrypted"` | ||
Server string `json:"db_server"` | ||
Port int `json:"db_port"` | ||
Description string `json:"description"` | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
ConnectionString string `json:"db_connection_string"` | ||
Default bool `json:"default"` | ||
} |
123 changes: 123 additions & 0 deletions
123
services/settings/database_settings/database_settings_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package database_settings | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// unnmarshalTest stolen from policy tests - we can probably generalize this to be reused across areas better | ||
type unmarshalTest struct { | ||
name string | ||
json string | ||
expectedErr bool | ||
expected Databases | ||
} | ||
|
||
// runUnmarshalTest runs the unmarshal test. | ||
func runUnmarshalTest(t *testing.T, tests []unmarshalTest) { | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var actual Databases | ||
if !tt.expectedErr { | ||
assert.NoError(t, json.Unmarshal([]byte(tt.json), &actual)) | ||
assert.EqualValues(t, actual, tt.expected) | ||
} else { | ||
assert.Error(t, json.Unmarshal([]byte(tt.json), &actual)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// TestDatabaseUnmarshal tests unmarshalling the database settings | ||
func TestDatabaseUnmarshal(t *testing.T) { | ||
tests := []unmarshalTest{ | ||
{ | ||
name: "Generic database settings unmarshal test", | ||
json: `{"databases": [{"enabled": true, | ||
"db_name": "testingdb", | ||
"db_username": "test_user", | ||
"db_password": "test_pw", | ||
"db_server": "test_server", | ||
"db_port": 5, | ||
"description": "Some desc", | ||
"name": "New DB Source", | ||
"type": "DB Type 5", | ||
"default": false, | ||
"db_connection_string": "asdfasdfasdf" | ||
}]}`, | ||
expectedErr: false, | ||
expected: Databases{ | ||
[]Database{ | ||
{ | ||
Enabled: true, | ||
Database: "testingdb", | ||
UserName: "test_user", | ||
Password: "test_pw", | ||
Server: "test_server", | ||
Port: 5, | ||
Description: "Some desc", | ||
Name: "New DB Source", | ||
Type: "DB Type 5", | ||
Default: false, | ||
ConnectionString: "asdfasdfasdf", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Default sqlite DB test", | ||
json: `{"databases": [ | ||
{ | ||
"db_connection_string": "sqlite:///tmp/reports.db", | ||
"db_name": "reports.db", | ||
"db_username": "", | ||
"db_password": "", | ||
"db_server": "", | ||
"db_port": 0, | ||
"description": "Local reports database", | ||
"enabled": true, | ||
"id": "66a6bc90-2f5e-4dc3-8180-a7cf4133daf2", | ||
"name": "Local DB", | ||
"type": "sqlite", | ||
"default": true | ||
}]}`, | ||
expectedErr: false, | ||
expected: Databases{ | ||
[]Database{ | ||
{ | ||
Enabled: true, | ||
ConnectionString: "sqlite:///tmp/reports.db", | ||
Database: "reports.db", | ||
UserName: "", | ||
Password: "", | ||
Server: "", | ||
Port: 0, | ||
Description: "Local reports database", | ||
Name: "Local DB", | ||
Type: "sqlite", | ||
Default: true, | ||
ID: "66a6bc90-2f5e-4dc3-8180-a7cf4133daf2", | ||
}, | ||
}, | ||
}}, | ||
{ | ||
name: "bad rule object type", | ||
json: `{"name": "Geo Rule Tester", | ||
"id": "c2428365-65be-4901-bfc0-bde2b310fedf", | ||
"type": "asdfasdf", | ||
"description": "Whatever", | ||
"conditions": ["1458dc12-a9c2-4d0c-8203-1340c61c2c3b"], | ||
"action": { | ||
"type": "SET_CONFIGURATION", | ||
"configuration_id": "1202b42e-2f21-49e9-b42c-5614e04d0031", | ||
"key": "GeoipRuleObject" | ||
} | ||
}`, | ||
expectedErr: false, | ||
expected: Databases{}, | ||
}, | ||
} | ||
runUnmarshalTest(t, tests) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package database_settings | ||
|
||
type Databases struct { | ||
Databases []Database `json:"databases"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters