Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Enterprise License tests #5822

Merged
merged 29 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
99d8a0f
applying expired license
Jun 29, 2020
3d8f7a0
applying expired license
Jun 29, 2020
40736bd
EP license unit test
Jul 2, 2020
5d60159
added unit test and invalid key
Jul 6, 2020
5765a5b
moved file
Jul 6, 2020
9ed6cb1
removed integration test
Jul 6, 2020
1c9c229
added integration test
Jul 10, 2020
3488093
added integration test
Jul 10, 2020
583b395
added integration test
Jul 13, 2020
9460301
removed p and w directory
Jul 13, 2020
9986e52
public key from var to const
Jul 13, 2020
d4915e7
updated the test
Jul 14, 2020
9695b75
addressed comments
Jul 15, 2020
318338b
addressed comments
Jul 15, 2020
59b1519
removed a comment
Jul 15, 2020
f42f378
checking user information after applying license
Jul 16, 2020
73b66d1
changed the name of the test file
Jul 16, 2020
26a52aa
moved the test file to systest folder as this is an integration test
Jul 16, 2020
ff76f4c
added http in front of address
Jul 16, 2020
a13358c
removed extra t.Log()
Jul 16, 2020
9176b00
created a new directory for the test
Jul 16, 2020
28bae01
changed the struct for errors and checking the errors for json.unmars…
Jul 16, 2020
49b1a3a
checking if the test is running or not
Jul 16, 2020
bd043bc
checking if the test is running or not
Jul 16, 2020
e6bf88c
checking if the test is running
Jul 16, 2020
1869f97
added dgraph license at the top of the file
Jul 16, 2020
bd91ab0
fix typo
Jul 16, 2020
7636f85
Merge branch 'master' into neeraj/LicenseTesting
Jul 16, 2020
2d9989f
changed offset for docker to 100
Jul 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions systest/license/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Auto-generated with: [compose -a 1 -z 1 -w]
#
version: "3.5"
services:
alpha1:
image: dgraph/dgraph:latest
container_name: alpha1
working_dir: /data/alpha1
labels:
cluster: test
ports:
- 8281:8281
- 9281:9281
volumes:
- type: bind
source: $GOPATH/bin
target: /gobin
read_only: true
command: /gobin/dgraph alpha -o 201 --my=alpha1:7281 --lru_mb=1024 --zero=zero1:5281
zero1:
image: dgraph/dgraph:latest
container_name: zero1
working_dir: /data/zero1
labels:
cluster: test
ports:
- 5281:5281
- 6281:6281
volumes:
- type: bind
source: $GOPATH/bin
target: /gobin
read_only: true
command: /gobin/dgraph zero -o 201 --idx=1 --my=zero1:5281 --logtostderr -v=2
--bindall
volumes: {}
130 changes: 130 additions & 0 deletions systest/license/license_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package main

import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"testing"

"github.com/dgraph-io/dgraph/testutil"
"github.com/stretchr/testify/require"
)

var expiredKey = []byte(`-----BEGIN PGP MESSAGE-----

owEBwgI9/ZANAwAKAXomeeH3SyppAax7YgxsaWNlbnNlLmpzb25etF5+ewogICJ1
c2VyIjogIkRncmFwaCBUZXN0IEtleSIsCiAgIm1heF9ub2RlcyI6IDE4NDQ2NzQ0
MDczNzA5NTUxNjE1LAogICJleHBpcnkiOiAiMTk3MC0wMS0wMVQwMDowMDowMFoi
Cn0KiQIzBAABCgAdFiEED3lYS97wtaMT1MW+eiZ54fdLKmkFAl60Xn4ACgkQeiZ5
4fdLKmlVYQ//afX0H7Seb0ukxCMAcM8uqlBEGCEFv3K34avk1g8XRa6y4q/Ys0uU
DSaaDWdQ8IS5Q9SNlZBbJuqO6Pf1R01dEPTYQizWkDjYIBsY9xJnMZKEaA+F3bkn
8TXqI588+AvbqxHosz8cvh/nG+Ajk451rI9c2bqKB/FvH/zI6XyfUjqN+PvrqH0E
POA7nqSrWDemW4cMgNR4PhXehB/n2i3G6c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9LkLQYdnF1hEV+7++t2/uoaLDYbxYhUnXpJZxwCBX
DQTievpyQxDSEsYiSGhhap1e/tvf1VaZoFUuTYQQpiV7F47HzuifvqUy+9K3UrL0
SnJ5TRWS7cEKBLyZszrakGpqVakvEUlWO4wG0Fp4kUa4YXw8t58oqHRn9aAtoqJd
UOLnq2semUttaySR4DHhjneO3/RoVm79/aaqMi/QNJzc9Tt9nY0AgcYlA3bVXmAZ
nM9Rgi6SaO5DxnRdhFzZyYQMb4onFDI0eYMOhPm+NmKWplkFXB+mKPKj5o/pcEb4
SWHt8fUAWDLsmcJkY7/jo3hlK36GrLnNdN4IODqkooIixDmSay14aBmF08hQ1vt/
I8jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm7mUd/5nzcU5QZU9yEEI=
=2lFm
-----END PGP MESSAGE-----
`)

type responseStruct struct {
Errors json.RawMessage `json:"errors"`
Code string `json:"code"`
Message string `json:"message"`
License map[string]interface{} `json:"license"`
}

func TestEnterpriseLicense(t *testing.T) {

stateURL := "http://localhost:6281/state"
enterpriseLicenseURL := "http://localhost:6281/enterpriseLicense"

var tests = []struct {
name string
licenseKey []byte
expectError bool
code string
user string
licenseEnabled interface{}
}{
{
"Using expired entrerprise license key, should be able to extract user information",
expiredKey,
false,
`Success`,
`Dgraph Test Key`,
nil,
},
{
"Using invalid entrerprise license key should return an error",
invalidKey,
false,
``,
``,
nil,
},
{
"Using empty entrerprise license key should return an error",
[]byte(``),
false,
``,
``,
nil,
},
}
for _, tt := range tests {

// Apply the license
response, err := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(tt.licenseKey))
require.NoError(t, err)

var enterpriseResponse responseStruct
responseBody, err := ioutil.ReadAll(response.Body)
require.NoError(t, err)
json.Unmarshal(responseBody, &enterpriseResponse)

// Check if the license is applied
require.Equal(t, enterpriseResponse.Code, tt.code)

// Expired license should not be enabled even after it is applied
if enterpriseResponse.Code == `Success` {

response, err := http.Get(stateURL)
require.NoError(t, err)

var stateResponse responseStruct
responseBody, err := ioutil.ReadAll(response.Body)
require.NoError(t, err)
json.Unmarshal(responseBody, &stateResponse)

require.Equal(t, stateResponse.License["user"], tt.user)
require.Equal(t, stateResponse.License["enabled"], tt.licenseEnabled)
}
}
}