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

sh:nodeKind constraints not being enforced correctly #534

Closed
mpoffald opened this issue Jul 14, 2023 · 2 comments
Closed

sh:nodeKind constraints not being enforced correctly #534

mpoffald opened this issue Jul 14, 2023 · 2 comments
Labels
bug Something isn't working as expected

Comments

@mpoffald
Copy link
Contributor

It looks like (at least some) sh:nodeKind constraints are letting invalid transactions through.

Here are some tests that should pass, but currently fail:

(deftest ^:integration shacl-nodekind-constraints
  (testing "sh:Literal"
    (let [conn         (test-utils/create-conn)
          ledger       @(fluree/create conn "shacl/b" {:defaultContext ["" {:ex "http://example.org/ns/"}]})
          db-literal-names  @(fluree/stage
                               (fluree/db ledger)
                               {:id             :ex/UserShape
                                :type           [:sh/NodeShape]
                                :sh/targetClass :ex/User
                                :sh/property    [{:sh/path     :schema/name
                                                  ;;cannot be IRI or blank node
                                                  :sh/nodeKind :sh/Literal}]})
          invalid-db-iri-name  (try @(fluree/stage
                                       db-literal-names
                                       {:id          :ex/john
                                        :type        [:ex/User]
                                        :schema/name {:id :ex/Jack}})
                                    (catch Exception e e))
          invalid-db-blank-name  (try
                                   @(fluree/stage
                                      db-literal-names
                                      {:id          :ex/john
                                       :type        [:ex/User]
                                       :schema/name {:ex/firstName "John"}})
                                   (catch Exception e e))]
      (is (util/exception? invalid-db-iri-name))
      (is (util/exception? invalid-db-blank-name))))
  (testing "sh:IRIOrLiteral"
    (let [conn         (test-utils/create-conn)
          ledger       @(fluree/create conn "shacl/b" {:defaultContext ["" {:ex "http://example.org/ns/"}]})
          db-no-blank-countries  @(fluree/stage
                                  (fluree/db ledger)
                                  {:id             :ex/UserShape
                                   :type           [:sh/NodeShape]
                                   :sh/targetClass :ex/User
                                   :sh/property    [{:sh/path     :ex/country
                                                     ;;cannot be blank node
                                                     :sh/nodeKind  :sh/IRIOrLiteral}]})
          invalid-db-blank-country  (try
                                      @(fluree/stage
                                         db-no-blank-countries
                                         {:id          :ex/john
                                          :type        [:ex/User]
                                          :schema/name "John"
                                          :ex/country  {:ex/abbreviation "AU"}})
                                      (catch Exception e e))]
      (is (util/exception? invalid-db-blank-country))))
  (testing "sh:BlankNodeOrLiteral"
    (let [conn         (test-utils/create-conn)
          ledger       @(fluree/create conn "shacl/b" {:defaultContext ["" {:ex "http://example.org/ns/"}]})
          db-no-iri-jobs  @(fluree/stage
                             (fluree/db ledger)
                             {:id             :ex/UserShape
                              :type           [:sh/NodeShape]
                              :sh/targetClass :ex/User
                              :sh/property    [{:sh/path     :ex/occupation
                                                ;;cannot be IRI
                                                :sh/nodeKind :sh/BlankNodeOrLiteral}]})
          invalid-db-iri-job (try
                               @(fluree/stage
                                  db-no-iri-jobs
                                  {:id :ex/john
                                   :type [:ex/User]
                                   :schema/name "John"
                                   :ex/occupation {:id "Developer"}})
                               (catch Exception e e))]
      (is (util/exception? invalid-db-iri-job)))))

This is somewhat related to #533, which requires an sh:nodeKind implementation that specifically works on transacted flakes.

@mpoffald mpoffald added the bug Something isn't working as expected label Jul 14, 2023
@mpoffald
Copy link
Contributor Author

Note that there are no existing tests for sh:nodeKind, so it's unclear what may have broken this. Also, I didn't try all of the possible sh:nodeKinds, so it may be that the others work.

@dpetran
Copy link
Contributor

dpetran commented Aug 29, 2023

I believe this was fixed and tested in #557.

@dpetran dpetran closed this as completed Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

2 participants