From 99d8a0f2d8e3470298f5af3b1487d133c916365c Mon Sep 17 00:00:00 2001 From: antblood Date: Mon, 29 Jun 2020 06:49:31 +0530 Subject: [PATCH 01/28] applying expired license --- ee/acl/enterprise_test.go | 76 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 ee/acl/enterprise_test.go diff --git a/ee/acl/enterprise_test.go b/ee/acl/enterprise_test.go new file mode 100644 index 00000000000..b7cf9893348 --- /dev/null +++ b/ee/acl/enterprise_test.go @@ -0,0 +1,76 @@ +package acl + +import ( + "bytes" + "encoding/json" + "io/ioutil" + "net/http" + "reflect" + "testing" +) + +func TestEnterpriseLicense(t *testing.T) { + + 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/n2i3G6cPpwgCUd+N00N1f1mir/LmL6G5T4PrG + BmVz9fOdEr+U85PbMF9vOke9LkLQYdnF1hEV+7++t2/uoaLDYbxYhUnXpJZxwCBX + DQTievpyQF47HzuifvqUyxDSEsYiSGhhap1e/tvf1VaZoFUuTYQQpiV7+9K3UrL0 + SnJ5TRWS7cEKBLyZszrakGpqVakvEUlWO4wG0Fp4kUa4YXw8t58oqHRn9aAtoqJd + UOLnq2semUttaySR4DHhjneO3/RoVm79/aaqMi/QNJzc9Tt9nY0AgcYlA3bVXmAZ + nM9Rgi6SaO5DxnRdhFzZyYQMb4onFDI0eYMOhPm+NmKWplkFXB+mKPKj5o/pcEb4 + SWHt8fUAWDLsmcooIixDmSay14aBmF08hQ1vtJkY7/jo3hlK36GrLnNdN4IODqk/ + I8mUd/jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm75nzcU5QZU9yEEI= + =2lFm + -----END PGP MESSAGE----- + `) + enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" + resp, _ := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) + data, _ := ioutil.ReadAll(resp.Body) + var finalData interface{} + json.Unmarshal(data, &finalData) + xx := finalData.(map[string]interface{})["errors"] + t.Log("++++ errors +++\n", xx) + t.Log("burriha\n", (xx.([]interface{}))[0].(map[string]interface{})["message"]) + t.Log(reflect.TypeOf(xx)) + // for i := range finalData { + // t.Log("testsetet\n", i, finalData[i]) + // } + // vall := RetrieveDeepMap([]string{"errors", "message"}, finalData) + // t.Log("finalvalue", vall) + + // enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" + + // var tests = []struct { + // name string + // licenseKey []byte + // expectError bool + // expectedOutput string + // }{ + // { + // "Using expired entrerprised license key should return an error", + // expiredKey, + // false, + // `{"errors":[{"message":"while extracting enterprise details from the license: while decoding license file: EOF","extensions":{"code":"ErrorInvalidRequest"}}]}`, + // }, + // } + // for _, tt := range tests { + // t.Logf("Running: %s\n", tt.name) + // response, err := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) + // returnedOutput, err := ioutil.ReadAll(response.Body) + // if tt.expectError { + // require.Error(t, err) + // continue + // } + + // require.NoError(t, err) + // require.Equal(t, tt.expectedOutput, string(returnedOutput)) + // } + +} From 3d8f7a0822092960da2e4ce0f94a0eedd05589ac Mon Sep 17 00:00:00 2001 From: antblood Date: Mon, 29 Jun 2020 07:43:13 +0530 Subject: [PATCH 02/28] applying expired license --- ee/acl/enterprise_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/acl/enterprise_test.go b/ee/acl/enterprise_test.go index b7cf9893348..b9ea85dd2d3 100644 --- a/ee/acl/enterprise_test.go +++ b/ee/acl/enterprise_test.go @@ -37,7 +37,7 @@ func TestEnterpriseLicense(t *testing.T) { json.Unmarshal(data, &finalData) xx := finalData.(map[string]interface{})["errors"] t.Log("++++ errors +++\n", xx) - t.Log("burriha\n", (xx.([]interface{}))[0].(map[string]interface{})["message"]) + t.Log("woohoo\n", (xx.([]interface{}))[0].(map[string]interface{})["message"]) t.Log(reflect.TypeOf(xx)) // for i := range finalData { // t.Log("testsetet\n", i, finalData[i]) From 40736bdc8dff334d957ad5ebd7e7465c57551323 Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 2 Jul 2020 20:14:26 +0530 Subject: [PATCH 03/28] EP license unit test --- ee/acl/enterprise_test.go | 75 +++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/ee/acl/enterprise_test.go b/ee/acl/enterprise_test.go index b9ea85dd2d3..7bd5c6f4679 100644 --- a/ee/acl/enterprise_test.go +++ b/ee/acl/enterprise_test.go @@ -5,8 +5,9 @@ import ( "encoding/json" "io/ioutil" "net/http" - "reflect" "testing" + + "github.com/stretchr/testify/require" ) func TestEnterpriseLicense(t *testing.T) { @@ -30,47 +31,51 @@ func TestEnterpriseLicense(t *testing.T) { =2lFm -----END PGP MESSAGE----- `) - enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" - resp, _ := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) - data, _ := ioutil.ReadAll(resp.Body) - var finalData interface{} - json.Unmarshal(data, &finalData) - xx := finalData.(map[string]interface{})["errors"] - t.Log("++++ errors +++\n", xx) - t.Log("woohoo\n", (xx.([]interface{}))[0].(map[string]interface{})["message"]) - t.Log(reflect.TypeOf(xx)) + // enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" + // resp, _ := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) + // data, _ := ioutil.ReadAll(resp.Body) + // var finalData interface{} + // json.Unmarshal(data, &finalData) + // xx := finalData.(map[string]interface{})["errors"] + // t.Log("string of data\n", string(data)) + // t.Log("+++++ errors +++\n", xx) + // t.Log("woohoo\n", (xx.([]interface{}))[0].(map[string]interface{})["message"]) + // t.Log(reflect.TypeOf(xx)) // for i := range finalData { // t.Log("testsetet\n", i, finalData[i]) // } // vall := RetrieveDeepMap([]string{"errors", "message"}, finalData) // t.Log("finalvalue", vall) - // enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" + enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" - // var tests = []struct { - // name string - // licenseKey []byte - // expectError bool - // expectedOutput string - // }{ - // { - // "Using expired entrerprised license key should return an error", - // expiredKey, - // false, - // `{"errors":[{"message":"while extracting enterprise details from the license: while decoding license file: EOF","extensions":{"code":"ErrorInvalidRequest"}}]}`, - // }, - // } - // for _, tt := range tests { - // t.Logf("Running: %s\n", tt.name) - // response, err := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) - // returnedOutput, err := ioutil.ReadAll(response.Body) - // if tt.expectError { - // require.Error(t, err) - // continue - // } + var tests = []struct { + name string + licenseKey []byte + expectError bool + expectedOutput string + }{ + { + "Using expired entrerprised license key should return an error", + expiredKey, + false, + `while extracting enterprise details from the license: while decoding license file: EOF`, + }, + } + for _, tt := range tests { + t.Logf("Running: %s\n", tt.name) + response, err := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) + returnedOutput, err := ioutil.ReadAll(response.Body) + var finalData interface{} + json.Unmarshal(returnedOutput, &finalData) + errors := finalData.(map[string]interface{})["errors"].([]interface{})[0].(map[string]interface{})["message"] + if tt.expectError { + require.Error(t, err) + continue + } - // require.NoError(t, err) - // require.Equal(t, tt.expectedOutput, string(returnedOutput)) - // } + require.NoError(t, err) + require.Equal(t, tt.expectedOutput, errors) + } } From 5d6015913b47c3f0668610711724cf4c79262f85 Mon Sep 17 00:00:00 2001 From: antblood Date: Mon, 6 Jul 2020 10:53:43 +0530 Subject: [PATCH 04/28] added unit test and invalid key --- dgraph/cmd/zero/enterpriseExperiedKey.key | 18 +++++++ dgraph/cmd/zero/enterpriseInvalidKey.key | 18 +++++++ dgraph/cmd/zero/enterpriseUnit_test.go | 50 +++++++++++++++++++ dgraph/cmd/zero/license_ee.go | 14 ++++++ ...e_test.go => enterpriseIntegration_test.go | 4 +- 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 dgraph/cmd/zero/enterpriseExperiedKey.key create mode 100644 dgraph/cmd/zero/enterpriseInvalidKey.key create mode 100644 dgraph/cmd/zero/enterpriseUnit_test.go rename ee/acl/enterprise_test.go => enterpriseIntegration_test.go (97%) diff --git a/dgraph/cmd/zero/enterpriseExperiedKey.key b/dgraph/cmd/zero/enterpriseExperiedKey.key new file mode 100644 index 00000000000..dfc0c6caf16 --- /dev/null +++ b/dgraph/cmd/zero/enterpriseExperiedKey.key @@ -0,0 +1,18 @@ +-----BEGIN PGP MESSAGE----- + owEBwgI9/ZANAwAKAXomeeH3SyppAax7YgxsaWNlbnNlLmpzb25etF5+ewogICJ1 + c2VyIjogIkRncmFwaCBUZXN0IEtleSIsCiAgIm1heF9ub2RlcyI6IDE4NDQ2NzQ0 + MDczNzA5NTUxNjE1LAogICJleHBpcnkiOiAiMTk3MC0wMS0wMVQwMDowMDowMFoi + Cn0KiQIzBAABCgAdFiEED3lYS97wtaMT1MW+eiZ54fdLKmkFAl60Xn4ACgkQeiZ5 + 4fdLKmlVYQ//afX0H7Seb0ukxCMAcM8uqlBEGCEFv3K34avk1g8XRa6y4q/Ys0uU + DSaaDWdQ8IS5Q9SNlZBbJuqO6Pf1R01dEPTYQizWkDjYIBsY9xJnMZKEaA+F3bkn + 8TXqI588+AvbqxHosz8cvh/nG+Ajk451rI9c2bqKB/FvH/zI6XyfUjqN+PvrqH0E + POA7nqSrWDemW4cMgNR4PhXehB/n2i3G6cPpwgCUd+N00N1f1mir/LmL6G5T4PrG + BmVz9fOdEr+U85PbMF9vOke9LkLQYdnF1hEV+7++t2/uoaLDYbxYhUnXpJZxwCBX + DQTievpyQF47HzuifvqUyxDSEsYiSGhhap1e/tvf1VaZoFUuTYQQpiV7+9K3UrL0 + SnJ5TRWS7cEKBLyZszrakGpqVakvEUlWO4wG0Fp4kUa4YXw8t58oqHRn9aAtoqJd + UOLnq2semUttaySR4DHhjneO3/RoVm79/aaqMi/QNJzc9Tt9nY0AgcYlA3bVXmAZ + nM9Rgi6SaO5DxnRdhFzZyYQMb4onFDI0eYMOhPm+NmKWplkFXB+mKPKj5o/pcEb4 + SWHt8fUAWDLsmcooIixDmSay14aBmF08hQ1vtJkY7/jo3hlK36GrLnNdN4IODqk/ + I8mUd/jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm75nzcU5QZU9yEEI= + =2lFm + -----END PGP MESSAGE----- diff --git a/dgraph/cmd/zero/enterpriseInvalidKey.key b/dgraph/cmd/zero/enterpriseInvalidKey.key new file mode 100644 index 00000000000..e8667f8fee1 --- /dev/null +++ b/dgraph/cmd/zero/enterpriseInvalidKey.key @@ -0,0 +1,18 @@ +-----BEGIN PGP MESSAGE----- + owEBwgI9/ZANAwAKAXomeeH3SyppAax7YgxsaWNlbnNlLmpzb25etF5+ewogICJ1 + c2VyIjogIkRncmFwaCBUZXN0IEtleSIsCiAgIm1heF9ub2RlcyI6IDE4NDQ2NzQ0 + MDczNzA5NTUxNjE1LAogICJleHBpcnkiOiAiMTk3MC0wMS0wMVQwMDowaaawMFoi + Cn0KiQIzBAABCgAdFiEED3lYS97wtaMT1MW+eiZ54fdLKmkFAl60Xn4ACgkQeiZ5 + 4fdLKmlVYQ//afX0H7Seb0ukxCMAcM8uqlBEGCEFv3K34avk1g8XRaaa4q/Ys0uU + DSaaDWdQ8IS5Q9SNlZBbJuqO6Pf1R01dEPTYQizWkDjYIBsY9xJnMZKEaA+F3bkn + 8TXqI588+AvbqxHosz8cvh/nG+Ajk451rI9c2bqKB/FvH/zI6XyfUjqN+PvrqH0E + POA7nqSrWDemW4cMgNR4PhXehB/n2i3G6cPpwgCUd+N00N1f1mir/LmL6G5T4PrG + BmVz9fOdEr+U85aaaF9vOke9LkLQYdnF1hEV+7++t2/uoaLDYbxYaaaXpJZxwCBX + DQTievpyQF47HzuifvqUyxDSEsYiSGhhap1e/tvf1VaZoFUuTYQQaaa7+9K3UrL0 + SnJ5TRWS7cEKBLyZszrakGpqVakvEUlWO4wG0Fp4kUa4YXw8t58oqHRn9aAtoqJd + UOLnq2semUttayaaaDHhjneO3/RoVm79/aaqMi/QNJzc9Ttaaa0AgcYlA3bVXmAZ + nM9Rgi6SaO5DxnRdhFzZyYQMb4onFDI0eYMOhPm+NmKWplkFXB+mKPKj5o/pcEb4 + SWHt8fUAWDLsmaaaIixDmSay14aBmF08hQ1vtaaa7/jo3hlK36GrLnNdN4IODqk/ + I8mUd/jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm75nzcU5QZU9yEEI= + =2lFm + -----END PGP MESSAGE----- diff --git a/dgraph/cmd/zero/enterpriseUnit_test.go b/dgraph/cmd/zero/enterpriseUnit_test.go new file mode 100644 index 00000000000..51af7e18505 --- /dev/null +++ b/dgraph/cmd/zero/enterpriseUnit_test.go @@ -0,0 +1,50 @@ +package zero + +import ( + "testing" + + "github.com/dgraph-io/dgraph/protos/pb" + "github.com/stretchr/testify/require" +) + +func TestEnterpriseLicenseUnit(t *testing.T) { + + expiredKey := "enterpriseExperiedKey.Key" + invalidKey := "enterpriseInvalidKey.Key" + + var tests = []struct { + name string + licenseKeyPath string + expectError bool + expectedOutput string + }{ + { + "Using expired entrerprised license key should return an error", + expiredKey, + true, + `while extracting enterprise details from the license: while decoding license file: EOF`, + }, + { + "Using invalid entrerprised license key should return an error", + invalidKey, + true, + `while extracting enterprise details from the license: while decoding license file: EOF`, + }, + } + server := &Server{ + state: &pb.MembershipState{ + Groups: map[uint32]*pb.Group{1: {Members: map[uint64]*pb.Member{}}}, + }, + } + for _, tt := range tests { + t.Logf("Running: %s\n", tt.name) + err := server.applyLicenseFileReturnError(expiredKey) + if tt.expectError { + require.Error(t, err) + continue + } + + require.NoError(t, err) + } + +} diff --git a/dgraph/cmd/zero/license_ee.go b/dgraph/cmd/zero/license_ee.go index 29ff9f64c70..9520e3d2ffc 100644 --- a/dgraph/cmd/zero/license_ee.go +++ b/dgraph/cmd/zero/license_ee.go @@ -147,3 +147,17 @@ func (s *Server) applyLicenseFile(path string) { glog.Infof("Unable to apply license at %v due to error %v", path, err) } } + +func (s *Server) applyLicenseFileReturnError(path string) error { + content, err := ioutil.ReadFile(path) + if err != nil { + glog.Infof("Unable to apply license at %v due to error %v", path, err) + return err + } + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + if err = s.applyLicense(ctx, bytes.NewReader(content)); err != nil { + glog.Infof("Unable to apply license at %v due to error %v", path, err) + } + return err +} diff --git a/ee/acl/enterprise_test.go b/enterpriseIntegration_test.go similarity index 97% rename from ee/acl/enterprise_test.go rename to enterpriseIntegration_test.go index 7bd5c6f4679..7bc9781311a 100644 --- a/ee/acl/enterprise_test.go +++ b/enterpriseIntegration_test.go @@ -1,4 +1,4 @@ -package acl +package zero import ( "bytes" @@ -67,6 +67,8 @@ func TestEnterpriseLicense(t *testing.T) { response, err := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) returnedOutput, err := ioutil.ReadAll(response.Body) var finalData interface{} + t.Log(response) + t.Log("\nstatus\n", response) json.Unmarshal(returnedOutput, &finalData) errors := finalData.(map[string]interface{})["errors"].([]interface{})[0].(map[string]interface{})["message"] if tt.expectError { From 5765a5bddc0f9cee1cfc47439409f42ab50292ff Mon Sep 17 00:00:00 2001 From: antblood Date: Mon, 6 Jul 2020 17:49:10 +0530 Subject: [PATCH 05/28] moved file --- .../cmd/zero/enterpriseIntegration_test.go | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename enterpriseIntegration_test.go => dgraph/cmd/zero/enterpriseIntegration_test.go (100%) diff --git a/enterpriseIntegration_test.go b/dgraph/cmd/zero/enterpriseIntegration_test.go similarity index 100% rename from enterpriseIntegration_test.go rename to dgraph/cmd/zero/enterpriseIntegration_test.go From 9ed6cb199664eb9b72d0216e16fbcb234e185ddf Mon Sep 17 00:00:00 2001 From: antblood Date: Mon, 6 Jul 2020 19:46:59 +0530 Subject: [PATCH 06/28] removed integration test --- dgraph/cmd/zero/enterpriseIntegration_test.go | 83 ------------------- 1 file changed, 83 deletions(-) delete mode 100644 dgraph/cmd/zero/enterpriseIntegration_test.go diff --git a/dgraph/cmd/zero/enterpriseIntegration_test.go b/dgraph/cmd/zero/enterpriseIntegration_test.go deleted file mode 100644 index 7bc9781311a..00000000000 --- a/dgraph/cmd/zero/enterpriseIntegration_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package zero - -import ( - "bytes" - "encoding/json" - "io/ioutil" - "net/http" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestEnterpriseLicense(t *testing.T) { - - 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/n2i3G6cPpwgCUd+N00N1f1mir/LmL6G5T4PrG - BmVz9fOdEr+U85PbMF9vOke9LkLQYdnF1hEV+7++t2/uoaLDYbxYhUnXpJZxwCBX - DQTievpyQF47HzuifvqUyxDSEsYiSGhhap1e/tvf1VaZoFUuTYQQpiV7+9K3UrL0 - SnJ5TRWS7cEKBLyZszrakGpqVakvEUlWO4wG0Fp4kUa4YXw8t58oqHRn9aAtoqJd - UOLnq2semUttaySR4DHhjneO3/RoVm79/aaqMi/QNJzc9Tt9nY0AgcYlA3bVXmAZ - nM9Rgi6SaO5DxnRdhFzZyYQMb4onFDI0eYMOhPm+NmKWplkFXB+mKPKj5o/pcEb4 - SWHt8fUAWDLsmcooIixDmSay14aBmF08hQ1vtJkY7/jo3hlK36GrLnNdN4IODqk/ - I8mUd/jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm75nzcU5QZU9yEEI= - =2lFm - -----END PGP MESSAGE----- - `) - // enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" - // resp, _ := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) - // data, _ := ioutil.ReadAll(resp.Body) - // var finalData interface{} - // json.Unmarshal(data, &finalData) - // xx := finalData.(map[string]interface{})["errors"] - // t.Log("string of data\n", string(data)) - // t.Log("+++++ errors +++\n", xx) - // t.Log("woohoo\n", (xx.([]interface{}))[0].(map[string]interface{})["message"]) - // t.Log(reflect.TypeOf(xx)) - // for i := range finalData { - // t.Log("testsetet\n", i, finalData[i]) - // } - // vall := RetrieveDeepMap([]string{"errors", "message"}, finalData) - // t.Log("finalvalue", vall) - - enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" - - var tests = []struct { - name string - licenseKey []byte - expectError bool - expectedOutput string - }{ - { - "Using expired entrerprised license key should return an error", - expiredKey, - false, - `while extracting enterprise details from the license: while decoding license file: EOF`, - }, - } - for _, tt := range tests { - t.Logf("Running: %s\n", tt.name) - response, err := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) - returnedOutput, err := ioutil.ReadAll(response.Body) - var finalData interface{} - t.Log(response) - t.Log("\nstatus\n", response) - json.Unmarshal(returnedOutput, &finalData) - errors := finalData.(map[string]interface{})["errors"].([]interface{})[0].(map[string]interface{})["message"] - if tt.expectError { - require.Error(t, err) - continue - } - - require.NoError(t, err) - require.Equal(t, tt.expectedOutput, errors) - } - -} From 1c9c229d149b64bf56416c40f6f1846d12429d6a Mon Sep 17 00:00:00 2001 From: antblood Date: Fri, 10 Jul 2020 13:30:53 +0530 Subject: [PATCH 07/28] added integration test --- compose/p/000000.vlog | Bin 0 -> 831 bytes compose/p/000006.sst | Bin 0 -> 481 bytes compose/p/KEYREGISTRY | 1 + compose/p/MANIFEST | Bin 0 -> 138 bytes compose/w/000000.vlog | Bin 0 -> 3244 bytes compose/w/000002.sst | Bin 0 -> 1052 bytes compose/w/KEYREGISTRY | 2 + compose/w/MANIFEST | Bin 0 -> 52 bytes dgraph/cmd/zero/enterpriseIntegration_test.go | 87 ++++++++++++++++++ dgraph/cmd/zero/pgp.go | 2 +- 10 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 compose/p/000000.vlog create mode 100644 compose/p/000006.sst create mode 100644 compose/p/KEYREGISTRY create mode 100644 compose/p/MANIFEST create mode 100644 compose/w/000000.vlog create mode 100644 compose/w/000002.sst create mode 100644 compose/w/KEYREGISTRY create mode 100644 compose/w/MANIFEST create mode 100644 dgraph/cmd/zero/enterpriseIntegration_test.go diff --git a/compose/p/000000.vlog b/compose/p/000000.vlog new file mode 100644 index 0000000000000000000000000000000000000000..935cf805b4e061e1e15c832ac80a0f97d93ef84c GIT binary patch literal 831 zcmZQzfPi+F&`t8SyQi<@k5_hJ6q90LWZ+IoFG?)P&?~7dNc|51|G1C^1vn)bl~_|N z5|c{|7|)hO^E5CBGcqV9C8ngO7AclgN2ku`~haBQlU*^D~DGbz&-S?PI5`+gB%n296e>mWX MkDq3iKi_r$0O-0$MF0Q* literal 0 HcmV?d00001 diff --git a/compose/p/000006.sst b/compose/p/000006.sst new file mode 100644 index 0000000000000000000000000000000000000000..e300a0eecbdbb5f04806e907d572f25ba3c5f115 GIT binary patch literal 481 zcmdPcs{c3PB4a2g1Cy_=Q9<@3hQBLU310ZWTC1C-rv8jqr%M!9=eY^Te(iJM6`XzH zg-6d<53Q3ERg{%ywMF^dXJ@KE$ky)G!E*P-_Ltuun?DwRH2s%tUHAXQhEw*P0e(Ho zhJs!R!TGi)Pv?f!L=FIdZ-1m8UEd0}?%n`{18Ir+>z6rV3$RJAp1 zxq!OWH1k7mOIg;|%GwqyPkXfPj9OI*BXi0tgN%Y3)(XNacVCGKIDN%|PmS*nyS$-7 zff7?|wRd0oT`p~A#UouS6OK>6#QM1AQp6!hJ8@KyqeSF`4pzD~?w$92z zi`VgaN(a*8q$}7Caj9_0Gca(cq!%R?WayPt7Njyj0pouN_$jf4NvNb+$t^RdB(*3w zwM5BE$a%+BoYO!+`_V4`SL3>eZ#&CwQ$@>1Gr zS`ESniI50FfbgQhXfV+bj7DQ3Dx#REL3|;mK~NJB6TMO>r7bNj;?wE0lx8Px(&j$Q zJkRg>|DR`OG;QQdv~53kl0?@8QI=Iw zIT_)5Y!|!8LD=>%b{%HJ|5P{`1gW$$#n(#}IM@WTm8 zoB@Fow5C^10UYcw!Z2l?%N^u+6uX$GB8EOf)c@S#Z3?0Rmk)GqhGfVuSx6@97s*0a zxu_j`!xcLeBjgcA2_s%Ap3H^Xw`PuP+4sTW17yt|&o5M$*)Pfr4Fwvq6{kVQ*qURO3^%fsjOEm=Xi7IW%x-CGtT&?2*`fN@bZraL zN2H_-+1&QH!zrblQByiB}AWq$hPhl0#c4R!W0qE5pmZA zDN}|KxK+Y+SxxKJ0`v(1vdg;L&MCn9_{N=Q!32M2BND7vfJLOUoO6a5=A1wuK|^^C zm(Fhb;+LI2?QY*(5v^Zcq{iwMSdnAr(E-2;_?%t67?l?vZvd_;Kf$7st4DA}EoM#w z*8WPpCP21ZTAR<<}Q0 zID0VOKu;9{XUdN=CONMN&X`sC|D0k@F-Nw;xI z=06o=-IzRbbWyL0ELW0U7G$|VCM0s1Lok6EbO?yWDV#8={A3=q!P%|HGH+}=m}%E{ z9^JM?O?Fw3<-U1f*`o@w%b2dK?ph6G3;f*8lVn|jEYC`rGa-GJRT?uVbYbhtx^YKH zl{`Xhn^Mq}Fb6YEY?n~hcq4m~nz&04=dr$%uPTVUuv6CfhXKUIk2o%gFA3tfRUr-< z7p8#_o54WCP7mMF2rl}rsbF#nkBgZL&E^#=9Vjadj>eyuQjA=w&(nV2H{tHXXPAf{f zh`pNVjL+2}IzXq747YMwp8uf1>stO zxjtJ{hZTjT*cOXRR7-8-3;Eg`PGqIvE7vKdLU$wS2y{cht bb4#U%7&6R6xZ<}Ndlb<#Ha@lEhoAog!!GWT literal 0 HcmV?d00001 diff --git a/compose/w/000002.sst b/compose/w/000002.sst new file mode 100644 index 0000000000000000000000000000000000000000..24053b189c28d66fa79fe3e6236f53c2cd1b831b GIT binary patch literal 1052 zcmV+%1mpWCwJ-f(v;{>Q0Cw@CL-3Z;0u-#Z7N^kVjj{OI?3Q{DUUf4nH)m=Yu@Ojv zyIMvNF&5d_0bZ0UNlHpe3K8nhBo1!}g-- z`%W!u*15_|`7+8NX~U_elmp?$!;3~BQt)92HXSo0nS&8IP~bSBqeh5*^VIcjT=$-O z>b*CX1fwAAro9+%sV}b5PPyf_4I%&~00I?XENR?&HYxM9c2+sC|~7If)q)mCGTbEbRZ`yj#~kY1a$zIWHT zuiaGJ0ow-BB+v>ztio1`Ekar<=+fPNYu<|D67h%1_z& zDG@()|L5a>E&f;fAN+sgKZ^es{!{qRU`C3KP6iUrK`SQyANXM+ooZrmPBbPGhL{WZ zx6p%BPR$kCpwu#tbaFV<+>lBfZb00F1+;&L=hsj==-34>XknEG(^X8hq`TfZE1dyw zsBvh-(1-wp0{~%RE8qeE7&2}Vz$E4^83D8er4{r5mUze>Q#?T;EbW~Bt_CPV5igK! zQF1gN%3^*|W@66uV2KcaK~R=54n9ap9*$@3#F6J#m$G*)v6d%g+BQA15ZZ)bNwI9WkdMnOSE zK~ifk&3;+NCoDlec`L7KC000K*2;YVP literal 0 HcmV?d00001 diff --git a/compose/w/KEYREGISTRY b/compose/w/KEYREGISTRY new file mode 100644 index 00000000000..7569eeaa138 --- /dev/null +++ b/compose/w/KEYREGISTRY @@ -0,0 +1,2 @@ + +c¾€Ó›ìU8)ÄÒ >p2Hello Badger \ No newline at end of file diff --git a/compose/w/MANIFEST b/compose/w/MANIFEST new file mode 100644 index 0000000000000000000000000000000000000000..5c6b3b42a6d302c7bbd2b5cad4c36fa0a3400b8a GIT binary patch literal 52 vcmZ=tNiSkxU| literal 0 HcmV?d00001 diff --git a/dgraph/cmd/zero/enterpriseIntegration_test.go b/dgraph/cmd/zero/enterpriseIntegration_test.go new file mode 100644 index 00000000000..e4b68fba2c6 --- /dev/null +++ b/dgraph/cmd/zero/enterpriseIntegration_test.go @@ -0,0 +1,87 @@ +package zero + +import ( + "bytes" + "crypto" + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "testing" + + "github.com/stretchr/testify/require" + "golang.org/x/crypto/openpgp" + "golang.org/x/crypto/openpgp/packet" +) + +func TestEnterpriseLicense(t *testing.T) { + + 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/n2i3G6cPpwgCUd+N00N1f1mir/LmL6G5T4PrG + BmVz9fOdEr+U85PbMF9vOke9LkLQYdnF1hEV+7++t2/uoaLDYbxYhUnXpJZxwCBX + DQTievpyQF47HzuifvqUyxDSEsYiSGhhap1e/tvf1VaZoFUuTYQQpiV7+9K3UrL0 + SnJ5TRWS7cEKBLyZszrakGpqVakvEUlWO4wG0Fp4kUa4YXw8t58oqHRn9aAtoqJd + UOLnq2semUttaySR4DHhjneO3/RoVm79/aaqMi/QNJzc9Tt9nY0AgcYlA3bVXmAZ + nM9Rgi6SaO5DxnRdhFzZyYQMb4onFDI0eYMOhPm+NmKWplkFXB+mKPKj5o/pcEb4 + SWHt8fUAWDLsmcooIixDmSay14aBmF08hQ1vtJkY7/jo3hlK36GrLnNdN4IODqk/ + I8mUd/jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm75nzcU5QZU9yEEI= + =2lFm + -----END PGP MESSAGE----- + `) + + enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" + correctEntity, _ := openpgp.NewEntity("correct", "", "correct@correct.com", &packet.Config{ + RSABits: 4096, + DefaultHash: crypto.SHA512, + }) + correctJSON := `{"user": "user", "max_nodes": 10, "expiry": "2021-08-16T19:09:06+10:00"}` + buf := signAndWriteMessage(t, correctEntity, correctJSON) + publicKey = fmt.Sprintf("%v", correctEntity.PrimaryKey.PublicKey) + publicKeyLocal := encodePublicKey(t, correctEntity) + e := license{} + t.Log(buf) + _ = verifySignature(buf, publicKeyLocal, &e) + t.Log(buf) + response, _ := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(buf.Bytes())) + returnedOutput1, _ := ioutil.ReadAll(response.Body) + t.Log(string(returnedOutput1)) + + var tests = []struct { + name string + licenseKey []byte + expectError bool + expectedOutput string + }{ + { + "Using expired entrerprised license key should return an error", + expiredKey, + false, + `while extracting enterprise details from the license: while decoding license file: EOF`, + }, + } + for _, tt := range tests { + t.Logf("Running: %s\n", tt.name) + response, err := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) + returnedOutput, err := ioutil.ReadAll(response.Body) + var finalData interface{} + t.Log(response) + json.Unmarshal(returnedOutput, &finalData) + t.Log("\nstatus\n", finalData) + errors := finalData.(map[string]interface{})["errors"].([]interface{})[0].(map[string]interface{})["message"] + if tt.expectError { + require.Error(t, err) + continue + } + + require.NoError(t, err) + require.Equal(t, tt.expectedOutput, errors) + } + +} diff --git a/dgraph/cmd/zero/pgp.go b/dgraph/cmd/zero/pgp.go index 73be44dcf0e..dfe7dfae0bf 100644 --- a/dgraph/cmd/zero/pgp.go +++ b/dgraph/cmd/zero/pgp.go @@ -26,7 +26,7 @@ import ( "golang.org/x/crypto/openpgp/armor" ) -const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK----- +var publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK----- mQINBF1bQAwBEACe+uIPgsfTmgLVDlJhdfzUH+ff774fn/Lqf0kLactHR8I6yI3h JO6i47IhM45VJLY0ZzXntCaItavm35NGdVuA3yPJv7YkSLTPkg5D2VHyZknb52lD From 348809379034076d2d82d1fed3d147ea4fb4d504 Mon Sep 17 00:00:00 2001 From: antblood Date: Fri, 10 Jul 2020 17:03:18 +0530 Subject: [PATCH 08/28] added integration test --- dgraph/cmd/zero/enterpriseIntegration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dgraph/cmd/zero/enterpriseIntegration_test.go b/dgraph/cmd/zero/enterpriseIntegration_test.go index e4b68fba2c6..0ccdaa6c5f5 100644 --- a/dgraph/cmd/zero/enterpriseIntegration_test.go +++ b/dgraph/cmd/zero/enterpriseIntegration_test.go @@ -48,7 +48,7 @@ func TestEnterpriseLicense(t *testing.T) { e := license{} t.Log(buf) _ = verifySignature(buf, publicKeyLocal, &e) - t.Log(buf) + buf = signAndWriteMessage(t, correctEntity, correctJSON) response, _ := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(buf.Bytes())) returnedOutput1, _ := ioutil.ReadAll(response.Body) t.Log(string(returnedOutput1)) From 583b395a1b7435a35789d6f2bfa5f1851be52dbf Mon Sep 17 00:00:00 2001 From: antblood Date: Mon, 13 Jul 2020 14:10:44 +0530 Subject: [PATCH 09/28] added integration test --- dgraph/cmd/zero/enterpriseIntegration_test.go | 88 ++++++++----------- dgraph/cmd/zero/enterpriseUnit_test.go | 50 ----------- dgraph/cmd/zero/license_ee.go | 14 --- 3 files changed, 38 insertions(+), 114 deletions(-) delete mode 100644 dgraph/cmd/zero/enterpriseUnit_test.go diff --git a/dgraph/cmd/zero/enterpriseIntegration_test.go b/dgraph/cmd/zero/enterpriseIntegration_test.go index 0ccdaa6c5f5..4ea0e955c49 100644 --- a/dgraph/cmd/zero/enterpriseIntegration_test.go +++ b/dgraph/cmd/zero/enterpriseIntegration_test.go @@ -2,56 +2,41 @@ package zero import ( "bytes" - "crypto" - "encoding/json" - "fmt" "io/ioutil" "net/http" + "strings" "testing" "github.com/stretchr/testify/require" - "golang.org/x/crypto/openpgp" - "golang.org/x/crypto/openpgp/packet" ) -func TestEnterpriseLicense(t *testing.T) { +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/n2i3G6cPpwgCUd+N00N1f1mir/LmL6G5T4PrG +BmVz9fOdEr+U85PbMF9vOke9LkLQYdnF1hEV+7++t2/uoaLDYbxYhUnXpJZxwCBX +DQTievpyQF47HzuifvqUyxDSEsYiSGhhap1e/tvf1VaZoFUuTYQQpiV7+9K3UrL0 +SnJ5TRWS7cEKBLyZszrakGpqVakvEUlWO4wG0Fp4kUa4YXw8t58oqHRn9aAtoqJd +UOLnq2semUttaySR4DHhjneO3/RoVm79/aaqMi/QNJzc9Tt9nY0AgcYlA3bVXmAZ +nM9Rgi6SaO5DxnRdhFzZyYQMb4onFDI0eYMOhPm+NmKWplkFXB+mKPKj5o/pcEb4 +SWHt8fUAWDLsmcooIixDmSay14aBmF08hQ1vtJkY7/jo3hlK36GrLnNdN4IODqk/ +I8mUd/jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm75nzcU5QZU9yEEI= +=2lFm +-----END PGP MESSAGE----- +`) + +type responseStruct struct { + errors map[string]interface{} `json:"errors"` +} - 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/n2i3G6cPpwgCUd+N00N1f1mir/LmL6G5T4PrG - BmVz9fOdEr+U85PbMF9vOke9LkLQYdnF1hEV+7++t2/uoaLDYbxYhUnXpJZxwCBX - DQTievpyQF47HzuifvqUyxDSEsYiSGhhap1e/tvf1VaZoFUuTYQQpiV7+9K3UrL0 - SnJ5TRWS7cEKBLyZszrakGpqVakvEUlWO4wG0Fp4kUa4YXw8t58oqHRn9aAtoqJd - UOLnq2semUttaySR4DHhjneO3/RoVm79/aaqMi/QNJzc9Tt9nY0AgcYlA3bVXmAZ - nM9Rgi6SaO5DxnRdhFzZyYQMb4onFDI0eYMOhPm+NmKWplkFXB+mKPKj5o/pcEb4 - SWHt8fUAWDLsmcooIixDmSay14aBmF08hQ1vtJkY7/jo3hlK36GrLnNdN4IODqk/ - I8mUd/jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm75nzcU5QZU9yEEI= - =2lFm - -----END PGP MESSAGE----- - `) +func TestEnterpriseLicense(t *testing.T) { enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" - correctEntity, _ := openpgp.NewEntity("correct", "", "correct@correct.com", &packet.Config{ - RSABits: 4096, - DefaultHash: crypto.SHA512, - }) - correctJSON := `{"user": "user", "max_nodes": 10, "expiry": "2021-08-16T19:09:06+10:00"}` - buf := signAndWriteMessage(t, correctEntity, correctJSON) - publicKey = fmt.Sprintf("%v", correctEntity.PrimaryKey.PublicKey) - publicKeyLocal := encodePublicKey(t, correctEntity) - e := license{} - t.Log(buf) - _ = verifySignature(buf, publicKeyLocal, &e) - buf = signAndWriteMessage(t, correctEntity, correctJSON) - response, _ := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(buf.Bytes())) - returnedOutput1, _ := ioutil.ReadAll(response.Body) - t.Log(string(returnedOutput1)) var tests = []struct { name string @@ -60,28 +45,31 @@ func TestEnterpriseLicense(t *testing.T) { expectedOutput string }{ { - "Using expired entrerprised license key should return an error", + "Using expired entrerprise license key should return an error", expiredKey, false, `while extracting enterprise details from the license: while decoding license file: EOF`, }, + { + "Using invalid entrerprise license key should return an error", + []byte(``), + false, + `while extracting enterprise details from the license: while decoding license file: EOF`, + }, } for _, tt := range tests { t.Logf("Running: %s\n", tt.name) response, err := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) - returnedOutput, err := ioutil.ReadAll(response.Body) - var finalData interface{} - t.Log(response) - json.Unmarshal(returnedOutput, &finalData) - t.Log("\nstatus\n", finalData) - errors := finalData.(map[string]interface{})["errors"].([]interface{})[0].(map[string]interface{})["message"] + require.NoError(t, err) + responseBody, err := ioutil.ReadAll(response.Body) + require.NoError(t, err) + correctError := strings.Contains(string(responseBody), tt.expectedOutput) + // errors := unmarshaledBody.(map[string]interface{})["errors"].([]interface{})[0].(map[string]interface{})["message"] if tt.expectError { require.Error(t, err) continue } - require.NoError(t, err) - require.Equal(t, tt.expectedOutput, errors) + require.Equal(t, true, correctError) } - } diff --git a/dgraph/cmd/zero/enterpriseUnit_test.go b/dgraph/cmd/zero/enterpriseUnit_test.go deleted file mode 100644 index 51af7e18505..00000000000 --- a/dgraph/cmd/zero/enterpriseUnit_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package zero - -import ( - "testing" - - "github.com/dgraph-io/dgraph/protos/pb" - "github.com/stretchr/testify/require" -) - -func TestEnterpriseLicenseUnit(t *testing.T) { - - expiredKey := "enterpriseExperiedKey.Key" - invalidKey := "enterpriseInvalidKey.Key" - - var tests = []struct { - name string - licenseKeyPath string - expectError bool - expectedOutput string - }{ - { - "Using expired entrerprised license key should return an error", - expiredKey, - true, - `while extracting enterprise details from the license: while decoding license file: EOF`, - }, - { - "Using invalid entrerprised license key should return an error", - invalidKey, - true, - `while extracting enterprise details from the license: while decoding license file: EOF`, - }, - } - server := &Server{ - state: &pb.MembershipState{ - Groups: map[uint32]*pb.Group{1: {Members: map[uint64]*pb.Member{}}}, - }, - } - for _, tt := range tests { - t.Logf("Running: %s\n", tt.name) - err := server.applyLicenseFileReturnError(expiredKey) - if tt.expectError { - require.Error(t, err) - continue - } - - require.NoError(t, err) - } - -} diff --git a/dgraph/cmd/zero/license_ee.go b/dgraph/cmd/zero/license_ee.go index 9520e3d2ffc..29ff9f64c70 100644 --- a/dgraph/cmd/zero/license_ee.go +++ b/dgraph/cmd/zero/license_ee.go @@ -147,17 +147,3 @@ func (s *Server) applyLicenseFile(path string) { glog.Infof("Unable to apply license at %v due to error %v", path, err) } } - -func (s *Server) applyLicenseFileReturnError(path string) error { - content, err := ioutil.ReadFile(path) - if err != nil { - glog.Infof("Unable to apply license at %v due to error %v", path, err) - return err - } - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - if err = s.applyLicense(ctx, bytes.NewReader(content)); err != nil { - glog.Infof("Unable to apply license at %v due to error %v", path, err) - } - return err -} From 94603012eba36bfd32bc3e343c781c9af73bde60 Mon Sep 17 00:00:00 2001 From: antblood Date: Mon, 13 Jul 2020 14:14:00 +0530 Subject: [PATCH 10/28] removed p and w directory --- compose/p/000000.vlog | Bin 831 -> 0 bytes compose/p/000006.sst | Bin 481 -> 0 bytes compose/p/KEYREGISTRY | 1 - compose/p/MANIFEST | Bin 138 -> 0 bytes compose/w/000000.vlog | Bin 3244 -> 0 bytes compose/w/000002.sst | Bin 1052 -> 0 bytes compose/w/KEYREGISTRY | 2 -- compose/w/MANIFEST | Bin 52 -> 0 bytes 8 files changed, 3 deletions(-) delete mode 100644 compose/p/000000.vlog delete mode 100644 compose/p/000006.sst delete mode 100644 compose/p/KEYREGISTRY delete mode 100644 compose/p/MANIFEST delete mode 100644 compose/w/000000.vlog delete mode 100644 compose/w/000002.sst delete mode 100644 compose/w/KEYREGISTRY delete mode 100644 compose/w/MANIFEST diff --git a/compose/p/000000.vlog b/compose/p/000000.vlog deleted file mode 100644 index 935cf805b4e061e1e15c832ac80a0f97d93ef84c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 831 zcmZQzfPi+F&`t8SyQi<@k5_hJ6q90LWZ+IoFG?)P&?~7dNc|51|G1C^1vn)bl~_|N z5|c{|7|)hO^E5CBGcqV9C8ngO7AclgN2ku`~haBQlU*^D~DGbz&-S?PI5`+gB%n296e>mWX MkDq3iKi_r$0O-0$MF0Q* diff --git a/compose/p/000006.sst b/compose/p/000006.sst deleted file mode 100644 index e300a0eecbdbb5f04806e907d572f25ba3c5f115..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 481 zcmdPcs{c3PB4a2g1Cy_=Q9<@3hQBLU310ZWTC1C-rv8jqr%M!9=eY^Te(iJM6`XzH zg-6d<53Q3ERg{%ywMF^dXJ@KE$ky)G!E*P-_Ltuun?DwRH2s%tUHAXQhEw*P0e(Ho zhJs!R!TGi)Pv?f!L=FIdZ-1m8UEd0}?%n`{18Ir+>z6rV3$RJAp1 zxq!OWH1k7mOIg;|%GwqyPkXfPj9OI*BXi0tgN%Y3)(XNacVCGKIDN%|PmS*nyS$-7 zff7?|wRd0oT`p~A#UouS6OK>6#QM1AQp6!hJ8@KyqeSF`4pzD~?w$92z zi`VgaN(a*8q$}7Caj9_0Gca(cq!%R?WayPt7Njyj0pouN_$jf4NvNb+$t^RdB(*3w zwM5BE$a%+BoYO!+`_V4`SL3>eZ#&CwQ$@>1Gr zS`ESniI50FfbgQhXfV+bj7DQ3Dx#REL3|;mK~NJB6TMO>r7bNj;?wE0lx8Px(&j$Q zJkRg>|DR`OG;QQdv~53kl0?@8QI=Iw zIT_)5Y!|!8LD=>%b{%HJ|5P{`1gW$$#n(#}IM@WTm8 zoB@Fow5C^10UYcw!Z2l?%N^u+6uX$GB8EOf)c@S#Z3?0Rmk)GqhGfVuSx6@97s*0a zxu_j`!xcLeBjgcA2_s%Ap3H^Xw`PuP+4sTW17yt|&o5M$*)Pfr4Fwvq6{kVQ*qURO3^%fsjOEm=Xi7IW%x-CGtT&?2*`fN@bZraL zN2H_-+1&QH!zrblQByiB}AWq$hPhl0#c4R!W0qE5pmZA zDN}|KxK+Y+SxxKJ0`v(1vdg;L&MCn9_{N=Q!32M2BND7vfJLOUoO6a5=A1wuK|^^C zm(Fhb;+LI2?QY*(5v^Zcq{iwMSdnAr(E-2;_?%t67?l?vZvd_;Kf$7st4DA}EoM#w z*8WPpCP21ZTAR<<}Q0 zID0VOKu;9{XUdN=CONMN&X`sC|D0k@F-Nw;xI z=06o=-IzRbbWyL0ELW0U7G$|VCM0s1Lok6EbO?yWDV#8={A3=q!P%|HGH+}=m}%E{ z9^JM?O?Fw3<-U1f*`o@w%b2dK?ph6G3;f*8lVn|jEYC`rGa-GJRT?uVbYbhtx^YKH zl{`Xhn^Mq}Fb6YEY?n~hcq4m~nz&04=dr$%uPTVUuv6CfhXKUIk2o%gFA3tfRUr-< z7p8#_o54WCP7mMF2rl}rsbF#nkBgZL&E^#=9Vjadj>eyuQjA=w&(nV2H{tHXXPAf{f zh`pNVjL+2}IzXq747YMwp8uf1>stO zxjtJ{hZTjT*cOXRR7-8-3;Eg`PGqIvE7vKdLU$wS2y{cht bb4#U%7&6R6xZ<}Ndlb<#Ha@lEhoAog!!GWT diff --git a/compose/w/000002.sst b/compose/w/000002.sst deleted file mode 100644 index 24053b189c28d66fa79fe3e6236f53c2cd1b831b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1052 zcmV+%1mpWCwJ-f(v;{>Q0Cw@CL-3Z;0u-#Z7N^kVjj{OI?3Q{DUUf4nH)m=Yu@Ojv zyIMvNF&5d_0bZ0UNlHpe3K8nhBo1!}g-- z`%W!u*15_|`7+8NX~U_elmp?$!;3~BQt)92HXSo0nS&8IP~bSBqeh5*^VIcjT=$-O z>b*CX1fwAAro9+%sV}b5PPyf_4I%&~00I?XENR?&HYxM9c2+sC|~7If)q)mCGTbEbRZ`yj#~kY1a$zIWHT zuiaGJ0ow-BB+v>ztio1`Ekar<=+fPNYu<|D67h%1_z& zDG@()|L5a>E&f;fAN+sgKZ^es{!{qRU`C3KP6iUrK`SQyANXM+ooZrmPBbPGhL{WZ zx6p%BPR$kCpwu#tbaFV<+>lBfZb00F1+;&L=hsj==-34>XknEG(^X8hq`TfZE1dyw zsBvh-(1-wp0{~%RE8qeE7&2}Vz$E4^83D8er4{r5mUze>Q#?T;EbW~Bt_CPV5igK! zQF1gN%3^*|W@66uV2KcaK~R=54n9ap9*$@3#F6J#m$G*)v6d%g+BQA15ZZ)bNwI9WkdMnOSE zK~ifk&3;+NCoDlec`L7KC000K*2;YVP diff --git a/compose/w/KEYREGISTRY b/compose/w/KEYREGISTRY deleted file mode 100644 index 7569eeaa138..00000000000 --- a/compose/w/KEYREGISTRY +++ /dev/null @@ -1,2 +0,0 @@ - -c¾€Ó›ìU8)ÄÒ >p2Hello Badger \ No newline at end of file diff --git a/compose/w/MANIFEST b/compose/w/MANIFEST deleted file mode 100644 index 5c6b3b42a6d302c7bbd2b5cad4c36fa0a3400b8a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 52 vcmZ=tNiSkxU| From 9986e525b524fbcbbaa1346b5a2fee763179ef77 Mon Sep 17 00:00:00 2001 From: antblood Date: Mon, 13 Jul 2020 14:30:30 +0530 Subject: [PATCH 11/28] public key from var to const --- dgraph/cmd/zero/pgp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dgraph/cmd/zero/pgp.go b/dgraph/cmd/zero/pgp.go index dfe7dfae0bf..73be44dcf0e 100644 --- a/dgraph/cmd/zero/pgp.go +++ b/dgraph/cmd/zero/pgp.go @@ -26,7 +26,7 @@ import ( "golang.org/x/crypto/openpgp/armor" ) -var publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK----- +const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK----- mQINBF1bQAwBEACe+uIPgsfTmgLVDlJhdfzUH+ff774fn/Lqf0kLactHR8I6yI3h JO6i47IhM45VJLY0ZzXntCaItavm35NGdVuA3yPJv7YkSLTPkg5D2VHyZknb52lD From d4915e7e08bd2c9c074ba61c7a06ca8f5960441f Mon Sep 17 00:00:00 2001 From: antblood Date: Tue, 14 Jul 2020 07:37:45 +0530 Subject: [PATCH 12/28] updated the test --- dgraph/cmd/zero/enterpriseIntegration_test.go | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/dgraph/cmd/zero/enterpriseIntegration_test.go b/dgraph/cmd/zero/enterpriseIntegration_test.go index 4ea0e955c49..ec1250ab0e3 100644 --- a/dgraph/cmd/zero/enterpriseIntegration_test.go +++ b/dgraph/cmd/zero/enterpriseIntegration_test.go @@ -2,12 +2,19 @@ package zero import ( "bytes" + "context" + "flag" + "fmt" "io/ioutil" + "log" "net/http" "strings" "testing" + "github.com/dgraph-io/dgo" + "github.com/dgraph-io/dgo/protos/api" "github.com/stretchr/testify/require" + "google.golang.org/grpc" ) var expiredKey = []byte(`-----BEGIN PGP MESSAGE----- @@ -36,6 +43,32 @@ type responseStruct struct { func TestEnterpriseLicense(t *testing.T) { + var ( + dgraph = flag.String("d", "127.0.0.1:9080", "Dgraph Alpha address") + ) + + conn, err := grpc.Dial(*dgraph, grpc.WithInsecure()) + if err != nil { + log.Fatal(err) + } + defer conn.Close() + + dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) + + resp, err := dg.NewTxn().Query(context.Background(), `{ + getUser(name: "alice") { + name + groups { + name + } + } + }`) + + if err != nil { + log.Fatal(err) + } + fmt.Printf("Response: %s\n", resp.Json) + enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" var tests = []struct { From 9695b75e0176c90ba27e446552624f11587d5a86 Mon Sep 17 00:00:00 2001 From: antblood Date: Wed, 15 Jul 2020 23:14:31 +0530 Subject: [PATCH 13/28] addressed comments --- dgraph/cmd/zero/enterpriseIntegration_test.go | 36 +------------------ dgraph/cmd/zero/enterpriseInvalidKey.key | 18 ---------- 2 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 dgraph/cmd/zero/enterpriseInvalidKey.key diff --git a/dgraph/cmd/zero/enterpriseIntegration_test.go b/dgraph/cmd/zero/enterpriseIntegration_test.go index ec1250ab0e3..95d21f9f92d 100644 --- a/dgraph/cmd/zero/enterpriseIntegration_test.go +++ b/dgraph/cmd/zero/enterpriseIntegration_test.go @@ -2,19 +2,12 @@ package zero import ( "bytes" - "context" - "flag" - "fmt" "io/ioutil" - "log" "net/http" "strings" "testing" - "github.com/dgraph-io/dgo" - "github.com/dgraph-io/dgo/protos/api" "github.com/stretchr/testify/require" - "google.golang.org/grpc" ) var expiredKey = []byte(`-----BEGIN PGP MESSAGE----- @@ -43,34 +36,7 @@ type responseStruct struct { func TestEnterpriseLicense(t *testing.T) { - var ( - dgraph = flag.String("d", "127.0.0.1:9080", "Dgraph Alpha address") - ) - - conn, err := grpc.Dial(*dgraph, grpc.WithInsecure()) - if err != nil { - log.Fatal(err) - } - defer conn.Close() - - dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) - - resp, err := dg.NewTxn().Query(context.Background(), `{ - getUser(name: "alice") { - name - groups { - name - } - } - }`) - - if err != nil { - log.Fatal(err) - } - fmt.Printf("Response: %s\n", resp.Json) - enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" - var tests = []struct { name string licenseKey []byte @@ -84,7 +50,7 @@ func TestEnterpriseLicense(t *testing.T) { `while extracting enterprise details from the license: while decoding license file: EOF`, }, { - "Using invalid entrerprise license key should return an error", + "Using empty entrerprise license key should return an error", []byte(``), false, `while extracting enterprise details from the license: while decoding license file: EOF`, diff --git a/dgraph/cmd/zero/enterpriseInvalidKey.key b/dgraph/cmd/zero/enterpriseInvalidKey.key deleted file mode 100644 index e8667f8fee1..00000000000 --- a/dgraph/cmd/zero/enterpriseInvalidKey.key +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN PGP MESSAGE----- - owEBwgI9/ZANAwAKAXomeeH3SyppAax7YgxsaWNlbnNlLmpzb25etF5+ewogICJ1 - c2VyIjogIkRncmFwaCBUZXN0IEtleSIsCiAgIm1heF9ub2RlcyI6IDE4NDQ2NzQ0 - MDczNzA5NTUxNjE1LAogICJleHBpcnkiOiAiMTk3MC0wMS0wMVQwMDowaaawMFoi - Cn0KiQIzBAABCgAdFiEED3lYS97wtaMT1MW+eiZ54fdLKmkFAl60Xn4ACgkQeiZ5 - 4fdLKmlVYQ//afX0H7Seb0ukxCMAcM8uqlBEGCEFv3K34avk1g8XRaaa4q/Ys0uU - DSaaDWdQ8IS5Q9SNlZBbJuqO6Pf1R01dEPTYQizWkDjYIBsY9xJnMZKEaA+F3bkn - 8TXqI588+AvbqxHosz8cvh/nG+Ajk451rI9c2bqKB/FvH/zI6XyfUjqN+PvrqH0E - POA7nqSrWDemW4cMgNR4PhXehB/n2i3G6cPpwgCUd+N00N1f1mir/LmL6G5T4PrG - BmVz9fOdEr+U85aaaF9vOke9LkLQYdnF1hEV+7++t2/uoaLDYbxYaaaXpJZxwCBX - DQTievpyQF47HzuifvqUyxDSEsYiSGhhap1e/tvf1VaZoFUuTYQQaaa7+9K3UrL0 - SnJ5TRWS7cEKBLyZszrakGpqVakvEUlWO4wG0Fp4kUa4YXw8t58oqHRn9aAtoqJd - UOLnq2semUttayaaaDHhjneO3/RoVm79/aaqMi/QNJzc9Ttaaa0AgcYlA3bVXmAZ - nM9Rgi6SaO5DxnRdhFzZyYQMb4onFDI0eYMOhPm+NmKWplkFXB+mKPKj5o/pcEb4 - SWHt8fUAWDLsmaaaIixDmSay14aBmF08hQ1vtaaa7/jo3hlK36GrLnNdN4IODqk/ - I8mUd/jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm75nzcU5QZU9yEEI= - =2lFm - -----END PGP MESSAGE----- From 318338b5637c080dcf0bf8c49f5c839fef82389d Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 00:03:23 +0530 Subject: [PATCH 14/28] addressed comments --- dgraph/cmd/zero/enterpriseExperiedKey.key | 18 ------------------ dgraph/cmd/zero/enterpriseIntegration_test.go | 4 ---- 2 files changed, 22 deletions(-) delete mode 100644 dgraph/cmd/zero/enterpriseExperiedKey.key diff --git a/dgraph/cmd/zero/enterpriseExperiedKey.key b/dgraph/cmd/zero/enterpriseExperiedKey.key deleted file mode 100644 index dfc0c6caf16..00000000000 --- a/dgraph/cmd/zero/enterpriseExperiedKey.key +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN PGP MESSAGE----- - owEBwgI9/ZANAwAKAXomeeH3SyppAax7YgxsaWNlbnNlLmpzb25etF5+ewogICJ1 - c2VyIjogIkRncmFwaCBUZXN0IEtleSIsCiAgIm1heF9ub2RlcyI6IDE4NDQ2NzQ0 - MDczNzA5NTUxNjE1LAogICJleHBpcnkiOiAiMTk3MC0wMS0wMVQwMDowMDowMFoi - Cn0KiQIzBAABCgAdFiEED3lYS97wtaMT1MW+eiZ54fdLKmkFAl60Xn4ACgkQeiZ5 - 4fdLKmlVYQ//afX0H7Seb0ukxCMAcM8uqlBEGCEFv3K34avk1g8XRa6y4q/Ys0uU - DSaaDWdQ8IS5Q9SNlZBbJuqO6Pf1R01dEPTYQizWkDjYIBsY9xJnMZKEaA+F3bkn - 8TXqI588+AvbqxHosz8cvh/nG+Ajk451rI9c2bqKB/FvH/zI6XyfUjqN+PvrqH0E - POA7nqSrWDemW4cMgNR4PhXehB/n2i3G6cPpwgCUd+N00N1f1mir/LmL6G5T4PrG - BmVz9fOdEr+U85PbMF9vOke9LkLQYdnF1hEV+7++t2/uoaLDYbxYhUnXpJZxwCBX - DQTievpyQF47HzuifvqUyxDSEsYiSGhhap1e/tvf1VaZoFUuTYQQpiV7+9K3UrL0 - SnJ5TRWS7cEKBLyZszrakGpqVakvEUlWO4wG0Fp4kUa4YXw8t58oqHRn9aAtoqJd - UOLnq2semUttaySR4DHhjneO3/RoVm79/aaqMi/QNJzc9Tt9nY0AgcYlA3bVXmAZ - nM9Rgi6SaO5DxnRdhFzZyYQMb4onFDI0eYMOhPm+NmKWplkFXB+mKPKj5o/pcEb4 - SWHt8fUAWDLsmcooIixDmSay14aBmF08hQ1vtJkY7/jo3hlK36GrLnNdN4IODqk/ - I8mUd/jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm75nzcU5QZU9yEEI= - =2lFm - -----END PGP MESSAGE----- diff --git a/dgraph/cmd/zero/enterpriseIntegration_test.go b/dgraph/cmd/zero/enterpriseIntegration_test.go index 95d21f9f92d..b22c3555128 100644 --- a/dgraph/cmd/zero/enterpriseIntegration_test.go +++ b/dgraph/cmd/zero/enterpriseIntegration_test.go @@ -30,10 +30,6 @@ I8mUd/jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm75nzcU5QZU9yEEI= -----END PGP MESSAGE----- `) -type responseStruct struct { - errors map[string]interface{} `json:"errors"` -} - func TestEnterpriseLicense(t *testing.T) { enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" From 59b1519cd07dff38922c191aaf05e5a2601e6ef3 Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 00:28:01 +0530 Subject: [PATCH 15/28] removed a comment --- dgraph/cmd/zero/enterpriseIntegration_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/dgraph/cmd/zero/enterpriseIntegration_test.go b/dgraph/cmd/zero/enterpriseIntegration_test.go index b22c3555128..4a83f40a933 100644 --- a/dgraph/cmd/zero/enterpriseIntegration_test.go +++ b/dgraph/cmd/zero/enterpriseIntegration_test.go @@ -59,7 +59,6 @@ func TestEnterpriseLicense(t *testing.T) { responseBody, err := ioutil.ReadAll(response.Body) require.NoError(t, err) correctError := strings.Contains(string(responseBody), tt.expectedOutput) - // errors := unmarshaledBody.(map[string]interface{})["errors"].([]interface{})[0].(map[string]interface{})["message"] if tt.expectError { require.Error(t, err) continue From f42f378ad8c0c23644e278deb9bd041260480e11 Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 12:42:44 +0530 Subject: [PATCH 16/28] checking user information after applying license --- dgraph/cmd/zero/enterpriseIntegration_test.go | 85 ++++++++++++++++--- 1 file changed, 73 insertions(+), 12 deletions(-) diff --git a/dgraph/cmd/zero/enterpriseIntegration_test.go b/dgraph/cmd/zero/enterpriseIntegration_test.go index 4a83f40a933..1c1713778e3 100644 --- a/dgraph/cmd/zero/enterpriseIntegration_test.go +++ b/dgraph/cmd/zero/enterpriseIntegration_test.go @@ -2,15 +2,16 @@ package zero import ( "bytes" + "encoding/json" "io/ioutil" "net/http" - "strings" "testing" "github.com/stretchr/testify/require" ) var expiredKey = []byte(`-----BEGIN PGP MESSAGE----- + owEBwgI9/ZANAwAKAXomeeH3SyppAax7YgxsaWNlbnNlLmpzb25etF5+ewogICJ1 c2VyIjogIkRncmFwaCBUZXN0IEtleSIsCiAgIm1heF9ub2RlcyI6IDE4NDQ2NzQ0 MDczNzA5NTUxNjE1LAogICJleHBpcnkiOiAiMTk3MC0wMS0wMVQwMDowMDowMFoi @@ -30,40 +31,100 @@ I8mUd/jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm75nzcU5QZU9yEEI= -----END PGP MESSAGE----- `) +var invalidKey = []byte(`-----BEGIN PGP MESSAGE----- + +x7YgxsaWNlbnNlLmpzb25etF5owEBwgI9omeeH3SyppAa/ZANAwAKAX+ewogICJ1 +c2VyIjogIkRncmFwaCBUZXN0IEtleSIsCiAgIm1heF9ub2RlcyI6IDE4NDQ2NzQ0 +MDczNzA5NTUxNjE1LAogICJleHBpcnkiOiAiMTk3MC0wMS0wMVQwMDowMDowMFoi +Cn0KiQIzBAABCgAdFiEED3lYS97wtaMT1MW+eiZ54fdLKmkFAl60Xn4ACgkQeiZ5 +4fdLKmlVYQ//afX0H7Seb0ukxCMAcM8uqlBEGCEFv3K34avk1g8XRa6y4q/Ys0uU +DSaaDWdQ8QizWkDjYIBsY9xJnMZKEaAIS5Q9SNlZBbJuqO6Pf1R01dEPTY+F3bkn +8T1rI9c2bqKB/FvH/zI6XXqI588+AvbqxHosz8cvh/nG+Ajk45yfUjqN+PvrqH0E +POA7nqSrWDemW4cMgNR4PhXehB/n2i3G6cPpwgCUd+N00N1f1mir/LmL6G5T4PrG +BmVz9fOdEr+U85PbMF9vOke9LkLQYdnF1hEV+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:6080/state" enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" + var tests = []struct { name string licenseKey []byte expectError bool - expectedOutput string + code string + user string + licenseEnabled interface{} }{ { - "Using expired entrerprise license key should return an error", + "Using expired entrerprise license key, should be able to extract user information", expiredKey, false, - `while extracting enterprise details from the license: while decoding license file: EOF`, + `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, - `while extracting enterprise details from the license: while decoding license file: EOF`, + ``, + ``, + nil, }, } for _, tt := range tests { + + // Apply the license t.Logf("Running: %s\n", tt.name) - response, err := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(expiredKey)) + 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) - correctError := strings.Contains(string(responseBody), tt.expectedOutput) - if tt.expectError { - require.Error(t, err) - continue + 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) } - require.NoError(t, err) - require.Equal(t, true, correctError) } } From 73b66d163fcc253e0c706750fc41ead26bb8b2f7 Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 12:47:03 +0530 Subject: [PATCH 17/28] changed the name of the test file --- .../cmd/zero/{enterpriseIntegration_test.go => license_test.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dgraph/cmd/zero/{enterpriseIntegration_test.go => license_test.go} (100%) diff --git a/dgraph/cmd/zero/enterpriseIntegration_test.go b/dgraph/cmd/zero/license_test.go similarity index 100% rename from dgraph/cmd/zero/enterpriseIntegration_test.go rename to dgraph/cmd/zero/license_test.go From 26a52aa57880ff973384578c7c95d7821303f66e Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 13:50:13 +0530 Subject: [PATCH 18/28] moved the test file to systest folder as this is an integration test --- {dgraph/cmd/zero => systest}/license_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename {dgraph/cmd/zero => systest}/license_test.go (95%) diff --git a/dgraph/cmd/zero/license_test.go b/systest/license_test.go similarity index 95% rename from dgraph/cmd/zero/license_test.go rename to systest/license_test.go index 1c1713778e3..a038bc9c26b 100644 --- a/dgraph/cmd/zero/license_test.go +++ b/systest/license_test.go @@ -1,4 +1,4 @@ -package zero +package main import ( "bytes" @@ -7,6 +7,7 @@ import ( "net/http" "testing" + "github.com/dgraph-io/dgraph/testutil" "github.com/stretchr/testify/require" ) @@ -61,9 +62,10 @@ type responseStruct struct { func TestEnterpriseLicense(t *testing.T) { - stateURL := "http://localhost:6080/state" - enterpriseLicenseURL := "http://localhost:6080/enterpriseLicense" + stateURL := testutil.SockAddrZeroHttp + "/state" + enterpriseLicenseURL := testutil.SockAddrZeroHttp + "/enterpriseLicense" + t.Log() var tests = []struct { name string licenseKey []byte @@ -100,7 +102,6 @@ func TestEnterpriseLicense(t *testing.T) { for _, tt := range tests { // Apply the license - t.Logf("Running: %s\n", tt.name) response, err := http.Post(enterpriseLicenseURL, "application/text", bytes.NewBuffer(tt.licenseKey)) require.NoError(t, err) From ff76f4c9e5c2beeb81a7f42c18f1d8c56c15030d Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 14:24:00 +0530 Subject: [PATCH 19/28] added http in front of address --- systest/license_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systest/license_test.go b/systest/license_test.go index a038bc9c26b..1cd8d460a3b 100644 --- a/systest/license_test.go +++ b/systest/license_test.go @@ -62,8 +62,8 @@ type responseStruct struct { func TestEnterpriseLicense(t *testing.T) { - stateURL := testutil.SockAddrZeroHttp + "/state" - enterpriseLicenseURL := testutil.SockAddrZeroHttp + "/enterpriseLicense" + stateURL := "http://" + testutil.SockAddrZeroHttp + "/state" + enterpriseLicenseURL := "http://" + testutil.SockAddrZeroHttp + "/enterpriseLicense" t.Log() var tests = []struct { From a13358c42b3a2bcb48a0fd327f0c469068529fae Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 14:26:33 +0530 Subject: [PATCH 20/28] removed extra t.Log() --- systest/license_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/systest/license_test.go b/systest/license_test.go index 1cd8d460a3b..3d4cbccf351 100644 --- a/systest/license_test.go +++ b/systest/license_test.go @@ -65,7 +65,6 @@ func TestEnterpriseLicense(t *testing.T) { stateURL := "http://" + testutil.SockAddrZeroHttp + "/state" enterpriseLicenseURL := "http://" + testutil.SockAddrZeroHttp + "/enterpriseLicense" - t.Log() var tests = []struct { name string licenseKey []byte From 9176b0040d8f91d145caf3dad6f89f4d4c1eaa6b Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 16:29:04 +0530 Subject: [PATCH 21/28] created a new directory for the test --- systest/license/docker-compose.yml | 36 +++++++++++++++++++++++++++ systest/{ => license}/license_test.go | 4 +-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 systest/license/docker-compose.yml rename systest/{ => license}/license_test.go (96%) diff --git a/systest/license/docker-compose.yml b/systest/license/docker-compose.yml new file mode 100644 index 00000000000..c607d9c36ca --- /dev/null +++ b/systest/license/docker-compose.yml @@ -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: {} diff --git a/systest/license_test.go b/systest/license/license_test.go similarity index 96% rename from systest/license_test.go rename to systest/license/license_test.go index 3d4cbccf351..d269928bfa5 100644 --- a/systest/license_test.go +++ b/systest/license/license_test.go @@ -62,8 +62,8 @@ type responseStruct struct { func TestEnterpriseLicense(t *testing.T) { - stateURL := "http://" + testutil.SockAddrZeroHttp + "/state" - enterpriseLicenseURL := "http://" + testutil.SockAddrZeroHttp + "/enterpriseLicense" + stateURL := "http://localhost:6281/state" + enterpriseLicenseURL := "http://localhost:6281/enterpriseLicense" var tests = []struct { name string From 28bae019859a895f675df28c0768eb629e4d4c57 Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 18:08:26 +0530 Subject: [PATCH 22/28] changed the struct for errors and checking the errors for json.unmarshal now --- systest/license/license_test.go | 52 +++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/systest/license/license_test.go b/systest/license/license_test.go index d269928bfa5..2bb286f3a8f 100644 --- a/systest/license/license_test.go +++ b/systest/license/license_test.go @@ -7,7 +7,6 @@ import ( "net/http" "testing" - "github.com/dgraph-io/dgraph/testutil" "github.com/stretchr/testify/require" ) @@ -53,8 +52,22 @@ I8jcj3NZtGWFoxKq4laK/ruoeoHnWMznJyMm7mUd/5nzcU5QZU9yEEI= -----END PGP MESSAGE----- `) +type Location struct { + Line int `json:"line,omitempty"` + Column int `json:"column,omitempty"` +} + +type GqlError struct { + Message string `json:"message"` + Locations []Location `json:"locations,omitempty"` + Path []interface{} `json:"path,omitempty"` + Extensions map[string]interface{} `json:"extensions,omitempty"` +} + +type GqlErrorList []*GqlError + type responseStruct struct { - Errors json.RawMessage `json:"errors"` + Errors GqlErrorList `json:"errors"` Code string `json:"code"` Message string `json:"message"` License map[string]interface{} `json:"license"` @@ -66,36 +79,32 @@ func TestEnterpriseLicense(t *testing.T) { enterpriseLicenseURL := "http://localhost:6281/enterpriseLicense" var tests = []struct { - name string - licenseKey []byte - expectError bool - code string - user string - licenseEnabled interface{} + name string + licenseKey []byte + code string + user string + message string }{ { "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, + `while extracting enterprise details from the license: while reading PGP message from license file: openpgp: unsupported feature: public key version`, }, { "Using empty entrerprise license key should return an error", []byte(``), - false, ``, ``, - nil, + `while extracting enterprise details from the license: while decoding license file: EOF`, }, } for _, tt := range tests { @@ -107,24 +116,31 @@ func TestEnterpriseLicense(t *testing.T) { var enterpriseResponse responseStruct responseBody, err := ioutil.ReadAll(response.Body) require.NoError(t, err) - json.Unmarshal(responseBody, &enterpriseResponse) + err = json.Unmarshal(responseBody, &enterpriseResponse) + require.NoError(t, err) // 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` { + // check the user information in case the license is applied + // Expired license should not be enabled even after it is applied + 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) + err = json.Unmarshal(responseBody, &stateResponse) + require.NoError(t, err) require.Equal(t, stateResponse.License["user"], tt.user) - require.Equal(t, stateResponse.License["enabled"], tt.licenseEnabled) + require.Equal(t, stateResponse.License["enabled"], nil) + } else { + // check the error message in case the license is not applied + require.Equal(t, enterpriseResponse.Errors[0].Message, tt.message) } } } From 49b1a3a413cea8ad2a93a41c3222ee9d599a5fcd Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 18:49:45 +0530 Subject: [PATCH 23/28] checking if the test is running or not --- systest/license/license_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/systest/license/license_test.go b/systest/license/license_test.go index 2bb286f3a8f..7eeb5aa51b6 100644 --- a/systest/license/license_test.go +++ b/systest/license/license_test.go @@ -74,6 +74,7 @@ type responseStruct struct { } func TestEnterpriseLicense(t *testing.T) { + t.Log("Running TestEnterpriseLicense\n") stateURL := "http://localhost:6281/state" enterpriseLicenseURL := "http://localhost:6281/enterpriseLicense" From bd043bc85148228e6b10742d7c1a10c44fb5d230 Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 19:38:44 +0530 Subject: [PATCH 24/28] checking if the test is running or not --- systest/loader/loader_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/systest/loader/loader_test.go b/systest/loader/loader_test.go index 3c2318877a9..92434a802c5 100644 --- a/systest/loader/loader_test.go +++ b/systest/loader/loader_test.go @@ -34,6 +34,7 @@ import ( ) func TestLoaderXidmap(t *testing.T) { + t.Log("TestLoaderXidmap\n") tmpDir, err := ioutil.TempDir("", "loader_test") require.NoError(t, err) defer os.RemoveAll(tmpDir) From e6bf88c823ab9f2dc98a45162169f9f7b7eb2f15 Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 20:14:12 +0530 Subject: [PATCH 25/28] checking if the test is running --- systest/license/license_test.go | 2 +- systest/loader/loader_test.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/systest/license/license_test.go b/systest/license/license_test.go index 7eeb5aa51b6..967c8d24ae5 100644 --- a/systest/license/license_test.go +++ b/systest/license/license_test.go @@ -98,7 +98,7 @@ func TestEnterpriseLicense(t *testing.T) { invalidKey, ``, ``, - `while extracting enterprise details from the license: while reading PGP message from license file: openpgp: unsupported feature: public key version`, + `while extracting enterprise detls from the license: while reading PGP message from license file: openpgp: unsupported feature: public key version`, }, { "Using empty entrerprise license key should return an error", diff --git a/systest/loader/loader_test.go b/systest/loader/loader_test.go index 92434a802c5..3c2318877a9 100644 --- a/systest/loader/loader_test.go +++ b/systest/loader/loader_test.go @@ -34,7 +34,6 @@ import ( ) func TestLoaderXidmap(t *testing.T) { - t.Log("TestLoaderXidmap\n") tmpDir, err := ioutil.TempDir("", "loader_test") require.NoError(t, err) defer os.RemoveAll(tmpDir) From 1869f9725fe641f001f30c8fb338975420d4ab50 Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 21:12:43 +0530 Subject: [PATCH 26/28] added dgraph license at the top of the file --- systest/license/license_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/systest/license/license_test.go b/systest/license/license_test.go index 967c8d24ae5..db031dd8048 100644 --- a/systest/license/license_test.go +++ b/systest/license/license_test.go @@ -1,3 +1,19 @@ +/* + * Copyright 2018 Dgraph Labs, Inc. and Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package main import ( From bd91ab0724c79e27ed08e959a0448747da090ae6 Mon Sep 17 00:00:00 2001 From: Ibrahim Jarif Date: Thu, 16 Jul 2020 21:27:46 +0530 Subject: [PATCH 27/28] fix typo --- systest/license/license_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systest/license/license_test.go b/systest/license/license_test.go index db031dd8048..ed8afd66f45 100644 --- a/systest/license/license_test.go +++ b/systest/license/license_test.go @@ -114,7 +114,7 @@ func TestEnterpriseLicense(t *testing.T) { invalidKey, ``, ``, - `while extracting enterprise detls from the license: while reading PGP message from license file: openpgp: unsupported feature: public key version`, + `while extracting enterprise details from the license: while reading PGP message from license file: openpgp: unsupported feature: public key version`, }, { "Using empty entrerprise license key should return an error", From 2d9989f0dbc46ffa60f9025c8c963be3475cbec7 Mon Sep 17 00:00:00 2001 From: antblood Date: Thu, 16 Jul 2020 22:44:13 +0530 Subject: [PATCH 28/28] changed offset for docker to 100 --- systest/license/docker-compose.yml | 12 ++++++------ systest/license/license_test.go | 7 +++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/systest/license/docker-compose.yml b/systest/license/docker-compose.yml index c607d9c36ca..f00460ffaa7 100644 --- a/systest/license/docker-compose.yml +++ b/systest/license/docker-compose.yml @@ -9,14 +9,14 @@ services: labels: cluster: test ports: - - 8281:8281 - - 9281:9281 + - 8180:8180 + - 9180:9180 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 + command: /gobin/dgraph alpha -o 100 --my=alpha1:7180 --lru_mb=1024 --zero=zero1:5180 zero1: image: dgraph/dgraph:latest container_name: zero1 @@ -24,13 +24,13 @@ services: labels: cluster: test ports: - - 5281:5281 - - 6281:6281 + - 5180:5180 + - 6180:6180 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 + command: /gobin/dgraph zero -o 100 --idx=1 --my=zero1:5180 --logtostderr -v=2 --bindall volumes: {} diff --git a/systest/license/license_test.go b/systest/license/license_test.go index ed8afd66f45..1223dc72409 100644 --- a/systest/license/license_test.go +++ b/systest/license/license_test.go @@ -90,10 +90,9 @@ type responseStruct struct { } func TestEnterpriseLicense(t *testing.T) { - t.Log("Running TestEnterpriseLicense\n") - stateURL := "http://localhost:6281/state" - enterpriseLicenseURL := "http://localhost:6281/enterpriseLicense" + stateURL := "http://localhost:6180/state" + enterpriseLicenseURL := "http://localhost:6180/enterpriseLicense" var tests = []struct { name string @@ -154,7 +153,7 @@ func TestEnterpriseLicense(t *testing.T) { require.NoError(t, err) require.Equal(t, stateResponse.License["user"], tt.user) - require.Equal(t, stateResponse.License["enabled"], nil) + require.Equal(t, stateResponse.License["enabled"], false) } else { // check the error message in case the license is not applied require.Equal(t, enterpriseResponse.Errors[0].Message, tt.message)