From 6a8f2a09f024a3adcc1bb1843f8db811017392d5 Mon Sep 17 00:00:00 2001 From: Robsdedude Date: Tue, 26 Dec 2023 00:21:55 +0100 Subject: [PATCH] GitHub Actions + pre-commit hooks --- .github/workflows/tests.yaml | 73 ++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 27 +++++++++++++ neo4j/src/driver/config.rs | 36 +++++++++--------- 3 files changed, 117 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/tests.yaml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..8e62b37 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,73 @@ +name: Tests +on: + push: + branches: + - ci + pull_request: +jobs: + tests: + name: Linting and Testing + runs-on: "ubuntu-latest" + strategy: + matrix: + rust-version: ["1.65", "stable"] + steps: + - name: Start Neo4j + run: docker run + -d --rm --name neo4j + -p 7474:7474 -p 7687:7687 + -e NEO4J_AUTH=neo4j/test + -e NEO4J_ACCEPT_LICENSE_AGREEMENT=yes + neo4j-enterprise:5.6 & + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@v1 + with: + toolchain: ${{ matrix.rust-version }} + components: clippy + - uses: dtolnay/rust-toolchain@nightly + with: + components: rustfmt + - name: cargo fmt + run: cargo +nightly fmt --all -- --check + - name: tests + env: + TEST_NEO4J_SCHEME: neo4j + TEST_NEO4J_HOST: localhost + TEST_NEO4J_PORT: 7687 + TEST_NEO4J_USER: neo4j + TEST_NEO4J_PASS: pass + TEST_NEO4J_EDITION: enterprise + TEST_NEO4J_VERSION: 5.6 + run: cargo test + testkit: + runs-on: ubuntu-latest + steps: + - name: Checkout driver + uses: actions/checkout@v4 + with: + path: driver + + # - name: Read required TestKit version from driver repo + # id: testkit_vars + # run: echo ::set-output name=testkit_version_ref::$(cat driver/.testkit_version | xargs) + + - name: Checkout TestKit + uses: actions/checkout@v4 + with: + repository: robsdedude/testkit + path: testkit + ref: rust + # ref: ${{ steps.testkit_vars.outputs.testkit_version_ref }} + + # Runs a single command using the runners shell + - name: Run TestKit + env: + # to learn what these variables do, see https://github.com/neo4j-drivers/testkit + TEST_DRIVER_NAME: rust + TEST_DRIVER_REPO: ${{ github.workspace }}/driver + TEST_RUN_ALL_TESTS: "true" + run: | + cd testkit + # everything from --run-only-selected is to reduce the number of tests run in this + # demonstation setup. In a real setup, you most likely don't want this. + python3 main.py --tests TESTKIT_TESTS STUB_TESTS TLS_TESTS diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6cd4150 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +fail_fast: true +repos: + - repo: local + hooks: + - id: check + name: cargo check + entry: cargo check -- + language: system + types: [rust] + pass_filenames: false + - id: fmt + name: cargo fmt + entry: cargo +nightly fmt --all -- --check + language: system + types: [rust] + - id: clippy + name: cargo clippy + entry: cargo clippy -- -D warnings + language: system + types: [rust] + pass_filenames: false + - id: unit + name: unit tests + entry: cargo test --tests --benches + language: system + types: [rust] + pass_filenames: false diff --git a/neo4j/src/driver/config.rs b/neo4j/src/driver/config.rs index 280fc9c..f6c5e82 100644 --- a/neo4j/src/driver/config.rs +++ b/neo4j/src/driver/config.rs @@ -541,13 +541,13 @@ impl ConnectionConfig { /// # use rustls::RootCertStore; /// # use rustls_pki_types::{TrustAnchor, Der}; /// - /// # fn get_client_config() -> ClientConfig { + /// # fn get_custom_client_config() -> ClientConfig { /// # ClientConfig::builder().with_root_certificates( /// # RootCertStore { /// # roots: vec![ /// # TrustAnchor { - /// # subject: Der::from_slice(b"1\x0b0\t\x06\x03U\x04\x06\x13\x02US1\"0 \x06\x03U\x04\n\x13\x19Google Trust Services LLC1\x140\x12\x06\x03U\x04\x03\x13\x0bGTS Root R4"), - /// # subject_public_key_info: Der::from_slice(b"0\x10\x06\x07*\x86H\xce=\x02\x01\x06\x05+\x81\x04\x00\"\x03b\x00\x04\xf3ts\xa7h\x8b`\xaeC\xb85\xc5\x810{KI\x9d\xfb\xc1a\xce\xe6\xdeF\xbdk\xd5a\x185\xae@\xdds\xf7\x89\x910Z\xeb<\xee\x85|\xa2@v;\xa9\xc6\xb8G\xd8*\xe7\x92\x91js\xe9\xb1r9\x9f)\x9f\xa2\x98\xd3_^X\x86e\x0f\xa1\x84e\x06\xd1\xdc\x8b\xc9\xc7s\xc8\x8cj/\xe5\xc4\xab\xd1\x1d\x8a"), + /// # subject: Der::from_slice(b""), + /// # subject_public_key_info: Der::from_slice(b""), /// # name_constraints: None, /// # }, /// # ], @@ -555,7 +555,7 @@ impl ConnectionConfig { /// # ).with_no_client_auth() /// # } /// # - /// let client_config: ClientConfig = get_client_config(); + /// let client_config: ClientConfig = get_custom_client_config(); /// let config = ConnectionConfig::new(("localhost", 7687).into()) /// .with_encryption_custom_tls_config(client_config); /// ``` @@ -854,21 +854,19 @@ mod mockable { impl NonVerifyingVerifier { pub fn new() -> Self { - let default_verifier = WebPkiServerVerifier::builder(Arc::new( - RootCertStore { - roots: vec![ - // any certificate will do as we only forward methods to the default - // verifier that do not care about the certificate - TrustAnchor { - subject: Der::from_slice(b"1\x0b0\t\x06\x03U\x04\x06\x13\x02US1\"0 \x06\x03U\x04\n\x13\x19Google Trust Services LLC1\x140\x12\x06\x03U\x04\x03\x13\x0bGTS Root R4"), - subject_public_key_info: Der::from_slice(b"0\x10\x06\x07*\x86H\xce=\x02\x01\x06\x05+\x81\x04\x00\"\x03b\x00\x04\xf3ts\xa7h\x8b`\xaeC\xb85\xc5\x810{KI\x9d\xfb\xc1a\xce\xe6\xdeF\xbdk\xd5a\x185\xae@\xdds\xf7\x89\x910Z\xeb<\xee\x85|\xa2@v;\xa9\xc6\xb8G\xd8*\xe7\x92\x91js\xe9\xb1r9\x9f)\x9f\xa2\x98\xd3_^X\x86e\x0f\xa1\x84e\x06\xd1\xdc\x8b\xc9\xc7s\xc8\x8cj/\xe5\xc4\xab\xd1\x1d\x8a"), - name_constraints: None - }, - ], - }, - )) - .build() - .unwrap(); + let default_verifier = WebPkiServerVerifier::builder(Arc::new(RootCertStore { + roots: vec![ + // any certificate will do as we only forward those methods to the default + // verifier which do not care about the certificate + TrustAnchor { + subject: Der::from_slice(b""), + subject_public_key_info: Der::from_slice(b""), + name_constraints: None, + }, + ], + })) + .build() + .unwrap(); let default_verifier = Arc::into_inner(default_verifier).unwrap(); Self { default_verifier } }