(t *testing.T)
| 2948 | } |
| 2949 | |
| 2950 | func TestLargeStringIndex(t *testing.T) { |
| 2951 | require.NoError(t, dropAll()) |
| 2952 | |
| 2953 | // Exact Index |
| 2954 | require.NoError(t, alterSchemaWithRetry(`name_exact: string @index(exact) .`)) |
| 2955 | bigval := strings.Repeat("biggest value", 7000) |
| 2956 | mu := fmt.Sprintf(`{ set { <0x01> <name_exact> "%v" . } }`, bigval) |
| 2957 | require.Contains(t, runMutation(mu).Error(), "value in the mutation is too large for the index") |
| 2958 | |
| 2959 | // Term Index |
| 2960 | require.NoError(t, alterSchemaWithRetry(`name_term: string @index(term) .`)) |
| 2961 | bigval = strings.Repeat("biggestvalue", 7000) |
| 2962 | mu = fmt.Sprintf(`{ set { <0x01> <name_term> "%v" . } }`, bigval) |
| 2963 | require.Contains(t, runMutation(mu).Error(), "value in the mutation is too large for the index") |
| 2964 | // while the value is large, term index is fine |
| 2965 | bigval = strings.Repeat("biggestvalue", 3000) |
| 2966 | mu = fmt.Sprintf(`{ set { <0x01> <name_term> "%v %v" . } }`, bigval, bigval) |
| 2967 | require.NoError(t, runMutation(mu)) |
| 2968 | |
| 2969 | // FullText Index |
| 2970 | require.NoError(t, alterSchemaWithRetry(`name_fulltext: string @index(fulltext) .`)) |
| 2971 | bigval = strings.Repeat("biggestvalue", 7000) |
| 2972 | mu = fmt.Sprintf(`{ set { <0x01> <name_fulltext> "%v" . } }`, bigval) |
| 2973 | require.Contains(t, runMutation(mu).Error(), "value in the mutation is too large for the index") |
| 2974 | // while the value is large, fulltext index is fine |
| 2975 | bigval = strings.Repeat("biggestvalue", 3000) |
| 2976 | mu = fmt.Sprintf(`{ set { <0x01> <name_fulltext> "%v %v" . } }`, bigval, bigval) |
| 2977 | require.NoError(t, runMutation(mu)) |
| 2978 | |
| 2979 | // Trigram Index |
| 2980 | require.NoError(t, alterSchemaWithRetry(`name_trigram: string @index(trigram) .`)) |
| 2981 | bigval = strings.Repeat("biggestvalue", 7000) |
| 2982 | mu = fmt.Sprintf(`{ set { <0x01> <name_trigram> "%v" . } }`, bigval) |
| 2983 | require.NoError(t, runMutation(mu)) |
| 2984 | |
| 2985 | // Large Predicate |
| 2986 | bigpred := strings.Repeat("large-predicate", 2000) |
| 2987 | require.NoError(t, alterSchemaWithRetry(fmt.Sprintf(`%v: string @index(exact) .`, bigpred))) |
| 2988 | bigval = strings.Repeat("biggestvalue", 3000) |
| 2989 | mu = fmt.Sprintf(`{ set { <0x01> <%v> "%v" . } }`, bigpred, bigval) |
| 2990 | require.Contains(t, runMutation(mu).Error(), "value in the mutation is too large for the index") |
| 2991 | |
| 2992 | // name_term has index term. Now, if we create an exact index, that will fail. |
| 2993 | // This is because one of the value has small terms but the whole value is bigger |
| 2994 | // than the limit. In such a case, indexing will fail and the schema should not change. |
| 2995 | require.NoError(t, alterSchemaWithRetry(`name_term: string @index(exact) .`)) |
| 2996 | dqlSchema, err := runGraphqlQuery(`schema{}`) |
| 2997 | require.NoError(t, err) |
| 2998 | require.Contains(t, dqlSchema, |
| 2999 | `{"predicate":"name_term","type":"string","index":true,"tokenizer":["term"]}`) |
| 3000 | } |
| 3001 | |
| 3002 | // TestDQLInjectionViaCondField is a security regression test for LEAD-001. |
| 3003 | // It verifies that a crafted cond field containing an injected DQL query block |
nothing calls this directly
no test coverage detected
searching dependent graphs…