Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
corepkgv2
Commits
2dc605b0
Commit
2dc605b0
authored
6 years ago
by
Ajit Jagtap
Browse files
Options
Downloads
Plain Diff
Merge branch 'msv_configBuilder' into 'devbranch'
Updated test cases - configmdl See merge request
!20
parents
41258384
c4e38392
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!23
Devbranch to Master
,
!20
Updated test cases - configmdl
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
configmdl/configmdl.go
+13
-12
configmdl/configmdl.go
configmdl/configmdl_test.go
+73
-2
configmdl/configmdl_test.go
with
86 additions
and
14 deletions
configmdl/configmdl.go
+
13
−
12
View file @
2dc605b0
package
configmdl
import
(
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/filemdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/securitymdl"
"github.com/BurntSushi/toml"
...
...
@@ -25,8 +26,8 @@ func InitConfigSecure(fpath string, config interface{}, key []byte) (toml.MetaDa
return
toml
.
MetaData
{},
fileReadErr
}
fileContent
,
decryptErr
:=
securitymdl
.
AESDecrypt
(
fileBytes
,
key
)
if
decryptErr
!=
nil
{
return
toml
.
MetaData
{},
decryptErr
if
errormdl
.
CheckErr2
(
decryptErr
)
!=
nil
{
return
toml
.
MetaData
{},
errormdl
.
CheckErr2
(
decryptErr
)
}
return
toml
.
Decode
(
string
(
fileContent
),
config
)
}
...
...
@@ -34,12 +35,12 @@ func InitConfigSecure(fpath string, config interface{}, key []byte) (toml.MetaDa
// SaveConfig - SaveConfig
func
SaveConfig
(
fpath
string
,
config
interface
{})
error
{
bytes
,
tomlMarshalError
:=
pellgotoml
.
Marshal
(
config
)
if
tomlMarshalError
!=
nil
{
return
tomlMarshalError
if
errormdl
.
CheckErr
(
tomlMarshalError
)
!=
nil
{
return
errormdl
.
CheckErr
(
tomlMarshalError
)
}
writeError
:=
filemdl
.
WriteFile
(
fpath
,
bytes
,
false
,
false
)
if
writeError
!=
nil
{
return
writeError
if
errormdl
.
CheckErr2
(
writeError
)
!=
nil
{
return
errormdl
.
CheckErr2
(
writeError
)
}
return
nil
}
...
...
@@ -47,19 +48,19 @@ func SaveConfig(fpath string, config interface{}) error {
// SaveConfigSecure - SaveConfigSecure
func
SaveConfigSecure
(
fpath
string
,
config
interface
{},
key
[]
byte
)
error
{
configBytes
,
tomlMarshalError
:=
pellgotoml
.
Marshal
(
config
)
if
tomlMarshalError
!=
nil
{
return
tomlMarshalError
if
errormdl
.
CheckErr
(
tomlMarshalError
)
!=
nil
{
return
errormdl
.
CheckErr
(
tomlMarshalError
)
}
encryptedBytes
,
encryptError
:=
securitymdl
.
AESEncrypt
(
configBytes
,
key
)
if
encryptError
!=
nil
{
return
encryptError
if
errormdl
.
CheckErr1
(
encryptError
)
!=
nil
{
return
errormdl
.
CheckErr1
(
encryptError
)
}
writeError
:=
filemdl
.
WriteFile
(
fpath
,
encryptedBytes
,
false
,
false
)
if
writeError
!=
nil
{
return
writeError
if
errormdl
.
CheckErr2
(
writeError
)
!=
nil
{
return
errormdl
.
CheckErr2
(
writeError
)
}
return
nil
}
This diff is collapsed.
Click to expand it.
configmdl/configmdl_test.go
+
73
−
2
View file @
2dc605b0
package
configmdl
import
(
"fmt"
"testing"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl"
"github.com/stretchr/testify/assert"
)
...
...
@@ -27,6 +28,24 @@ func TestSaveConfig(t *testing.T) {
assert
.
NoError
(
t
,
err
,
"This should not throw error"
)
}
func
Test1SaveConfig
(
t
*
testing
.
T
)
{
var
config
tomlConfig
InitConfig
(
"../testingdata/testData/config/config.toml"
,
&
config
)
errormdl
.
IsTestingNegetiveCaseOn
=
true
err
:=
SaveConfig
(
"../testingdata/testData/config/config-save.toml"
,
config
)
errormdl
.
IsTestingNegetiveCaseOn
=
false
assert
.
Error
(
t
,
err
,
"This should throw error"
)
}
func
Test2SaveConfig
(
t
*
testing
.
T
)
{
var
config
tomlConfig
InitConfig
(
"../testingdata/testData/config/config.toml"
,
&
config
)
errormdl
.
IsTestingNegetiveCaseOn2
=
true
err
:=
SaveConfig
(
"../testingdata/testData/config/config-save.toml"
,
config
)
errormdl
.
IsTestingNegetiveCaseOn2
=
false
assert
.
Error
(
t
,
err
,
"This should throw error"
)
}
func
TestSaveConfigSecure
(
t
*
testing
.
T
)
{
var
config
tomlConfig
InitConfig
(
"../testingdata/testData/config/config.toml"
,
&
config
)
...
...
@@ -35,6 +54,36 @@ func TestSaveConfigSecure(t *testing.T) {
assert
.
NoError
(
t
,
err
,
"This should not throw error"
)
}
func
Test1SaveConfigSecure
(
t
*
testing
.
T
)
{
var
config
tomlConfig
InitConfig
(
"../testingdata/testData/config/config.toml"
,
&
config
)
key
:=
"1234567891234567"
errormdl
.
IsTestingNegetiveCaseOn
=
true
err
:=
SaveConfigSecure
(
"../testingdata/testData/config/config-save-secure.toml"
,
config
,
[]
byte
(
key
))
errormdl
.
IsTestingNegetiveCaseOn
=
false
assert
.
Error
(
t
,
err
,
"This should throw error"
)
}
func
Test2SaveConfigSecure
(
t
*
testing
.
T
)
{
var
config
tomlConfig
InitConfig
(
"../testingdata/testData/config/config.toml"
,
&
config
)
key
:=
"1234567891234567"
errormdl
.
IsTestingNegetiveCaseOn1
=
true
err
:=
SaveConfigSecure
(
"../testingdata/testData/config/config-save-secure.toml"
,
config
,
[]
byte
(
key
))
errormdl
.
IsTestingNegetiveCaseOn1
=
false
assert
.
Error
(
t
,
err
,
"This should throw error"
)
}
func
Test3SaveConfigSecure
(
t
*
testing
.
T
)
{
var
config
tomlConfig
InitConfig
(
"../testingdata/testData/config/config.toml"
,
&
config
)
key
:=
"1234567891234567"
errormdl
.
IsTestingNegetiveCaseOn2
=
true
err
:=
SaveConfigSecure
(
"../testingdata/testData/config/config-save-secure.toml"
,
config
,
[]
byte
(
key
))
errormdl
.
IsTestingNegetiveCaseOn2
=
false
assert
.
Error
(
t
,
err
,
"This should throw error"
)
}
func
TestInitConfigSecure
(
t
*
testing
.
T
)
{
var
config
tomlConfig
InitConfig
(
"../testingdata/testData/config/config.toml"
,
&
config
)
...
...
@@ -42,6 +91,28 @@ func TestInitConfigSecure(t *testing.T) {
SaveConfigSecure
(
"../testingdata/testData/config/config-save-secure.toml"
,
config
,
[]
byte
(
key
))
_
,
err
:=
InitConfigSecure
(
"../testingdata/testData/config/config-save-secure.toml"
,
&
config
,
[]
byte
(
key
))
fmt
.
Println
(
"config: "
,
config
)
assert
.
NoError
(
t
,
err
,
"This should not throw error"
)
}
func
Test1InitConfigSecure
(
t
*
testing
.
T
)
{
var
config
tomlConfig
InitConfig
(
"../testingdata/testData/config/config.toml"
,
&
config
)
key
:=
"1234567891234567"
SaveConfigSecure
(
"../testingdata/testData/config/config-save-secure.toml"
,
config
,
[]
byte
(
key
))
_
,
err
:=
InitConfigSecure
(
"../testingdata/testData/config/config-save-secure.error"
,
&
config
,
[]
byte
(
key
))
assert
.
Error
(
t
,
err
,
"This should throw error"
)
}
func
Test2InitConfigSecure
(
t
*
testing
.
T
)
{
// errormdl.IsTestingNegetiveCaseOn = false
var
config
tomlConfig
InitConfig
(
"../testingdata/testData/config/config.toml"
,
&
config
)
key
:=
"1234567891234567"
SaveConfigSecure
(
"../testingdata/testData/config/config-save-secure.toml"
,
config
,
[]
byte
(
key
))
errormdl
.
IsTestingNegetiveCaseOn2
=
true
_
,
err
:=
InitConfigSecure
(
"../testingdata/testData/config/config-save-secure.toml"
,
&
config
,
[]
byte
(
key
))
errormdl
.
IsTestingNegetiveCaseOn2
=
false
assert
.
Error
(
t
,
err
,
"This should throw error"
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets