-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove auth error from mutation. (#6532)
- Loading branch information
Arijit Das
authored
Sep 21, 2020
1 parent
aea0af3
commit 302afc3
Showing
14 changed files
with
413 additions
and
154 deletions.
There are no files selected for viewing
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
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,136 @@ | ||
package debugoff | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/dgraph-io/dgraph/graphql/authorization" | ||
"github.com/dgraph-io/dgraph/graphql/e2e/common" | ||
"github.com/dgraph-io/dgraph/testutil" | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
metaInfo *testutil.AuthMeta | ||
) | ||
|
||
type TestCase struct { | ||
user string | ||
role string | ||
result string | ||
name string | ||
variables map[string]interface{} | ||
} | ||
|
||
func TestAddGQL(t *testing.T) { | ||
testCases := []TestCase{{ | ||
user: "user1", | ||
result: `{"addUserSecret":{"usersecret":[{"aSecret":"secret1"}]}}`, | ||
variables: map[string]interface{}{"user": &common.UserSecret{ | ||
ASecret: "secret1", | ||
OwnedBy: "user1", | ||
}}, | ||
}, { | ||
user: "user2", | ||
result: ``, | ||
variables: map[string]interface{}{"user": &common.UserSecret{ | ||
ASecret: "secret2", | ||
OwnedBy: "user1", | ||
}}, | ||
}} | ||
|
||
query := ` | ||
mutation addUser($user: AddUserSecretInput!) { | ||
addUserSecret(input: [$user]) { | ||
userSecret { | ||
aSecret | ||
} | ||
} | ||
} | ||
` | ||
var expected, result struct { | ||
AddUserSecret struct { | ||
UserSecret []*common.UserSecret | ||
} | ||
} | ||
|
||
for _, tcase := range testCases { | ||
getUserParams := &common.GraphQLParams{ | ||
Headers: common.GetJWT(t, tcase.user, tcase.role, metaInfo), | ||
Query: query, | ||
Variables: tcase.variables, | ||
} | ||
gqlResponse := getUserParams.ExecuteAsPost(t, common.GraphqlURL) | ||
if tcase.result == "" { | ||
require.Equal(t, len(gqlResponse.Errors), 0) | ||
continue | ||
} | ||
|
||
require.Nil(t, gqlResponse.Errors) | ||
|
||
err := json.Unmarshal([]byte(tcase.result), &expected) | ||
require.NoError(t, err) | ||
err = json.Unmarshal([]byte(gqlResponse.Data), &result) | ||
require.NoError(t, err) | ||
|
||
opt := cmpopts.IgnoreFields(common.UserSecret{}, "Id") | ||
if diff := cmp.Diff(expected, result, opt); diff != "" { | ||
t.Errorf("result mismatch (-want +got):\n%s", diff) | ||
} | ||
|
||
for _, i := range result.AddUserSecret.UserSecret { | ||
i.Delete(t, tcase.user, tcase.role, metaInfo) | ||
} | ||
} | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
schemaFile := "../schema.graphql" | ||
schema, err := ioutil.ReadFile(schemaFile) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
jsonFile := "../test_data.json" | ||
data, err := ioutil.ReadFile(jsonFile) | ||
if err != nil { | ||
panic(errors.Wrapf(err, "Unable to read file %s.", jsonFile)) | ||
} | ||
|
||
jwtAlgo := []string{authorization.HMAC256, authorization.RSA256} | ||
for _, algo := range jwtAlgo { | ||
authSchema, err := testutil.AppendAuthInfo(schema, algo, "../sample_public_key.pem") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
authMeta, err := authorization.Parse(string(authSchema)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
metaInfo = &testutil.AuthMeta{ | ||
PublicKey: authMeta.VerificationKey, | ||
Namespace: authMeta.Namespace, | ||
Algo: authMeta.Algo, | ||
Header: authMeta.Header, | ||
PrivateKeyPath: "../sample_private_key.pem", | ||
} | ||
|
||
common.BootstrapServer(authSchema, data) | ||
// Data is added only in the first iteration, but the schema is added every iteration. | ||
if data != nil { | ||
data = nil | ||
} | ||
exitCode := m.Run() | ||
if exitCode != 0 { | ||
os.Exit(exitCode) | ||
} | ||
} | ||
os.Exit(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,69 @@ | ||
version: "3.5" | ||
services: | ||
zero: | ||
image: dgraph/dgraph:latest | ||
container_name: zero1 | ||
working_dir: /data/zero1 | ||
ports: | ||
- 5180:5180 | ||
- 6180:6180 | ||
labels: | ||
cluster: test | ||
service: zero1 | ||
volumes: | ||
- type: bind | ||
source: $GOPATH/bin | ||
target: /gobin | ||
read_only: true | ||
command: /gobin/dgraph zero -o 100 --logtostderr -v=2 --bindall --expose_trace --profile_mode block --block_rate 10 --my=zero1:5180 | ||
|
||
alpha: | ||
image: dgraph/dgraph:latest | ||
container_name: alpha1 | ||
working_dir: /data/alpha1 | ||
volumes: | ||
- type: bind | ||
source: $GOPATH/bin | ||
target: /gobin | ||
read_only: true | ||
ports: | ||
- 8180:8180 | ||
- 9180:9180 | ||
labels: | ||
cluster: test | ||
service: alpha1 | ||
command: /gobin/dgraph alpha --lru_mb=1024 --zero=zero1:5180 -o 100 --expose_trace --trace 1.0 --profile_mode block --block_rate 10 --logtostderr -v=3 --whitelist 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 --my=alpha1:7180 | ||
|
||
zeroAdmin: | ||
image: dgraph/dgraph:latest | ||
container_name: zeroAdmin | ||
working_dir: /data/zeroAdmin | ||
ports: | ||
- 5280:5280 | ||
- 6280:6280 | ||
labels: | ||
cluster: admintest | ||
service: zeroAdmin | ||
volumes: | ||
- type: bind | ||
source: $GOPATH/bin | ||
target: /gobin | ||
read_only: true | ||
command: /gobin/dgraph zero -o 200 --logtostderr -v=2 --bindall --expose_trace --profile_mode block --block_rate 10 --my=zeroAdmin:5280 | ||
|
||
alphaAdmin: | ||
image: dgraph/dgraph:latest | ||
container_name: alphaAdmin | ||
working_dir: /data/alphaAdmin | ||
volumes: | ||
- type: bind | ||
source: $GOPATH/bin | ||
target: /gobin | ||
read_only: true | ||
ports: | ||
- 8280:8280 | ||
- 9280:9280 | ||
labels: | ||
cluster: admintest | ||
service: alphaAdmin | ||
command: /gobin/dgraph alpha --lru_mb=1024 --zero=zeroAdmin:5280 -o 200 --expose_trace --trace 1.0 --profile_mode block --block_rate 10 --logtostderr -v=2 --whitelist 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 --my=alphaAdmin:7280 |
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
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
Oops, something went wrong.