Skip to content

Commit

Permalink
Fix server tests. Add better comments in config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris committed Apr 5, 2023
1 parent 0c6a785 commit b9316e2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
20 changes: 13 additions & 7 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@ dotenv.config();

export default {
DID_CLIENT_CONFIG: {
network: EnvironmentType.TESTNET,
callType: 'web3',
web3Config: {
privateKey: ''
privateKey: '',
rpcUrl: 'https://rpc-mumbai.maticvigil.com'
},
},
ENVIRONMENT: EnvironmentType.TESTNET,
SERVER_URL: `http://localhost:5000`,
VDA_PRIVATE_KEY: '0x19d3b996ec98a9a536efdffbae41e5eaaf117765a587483c69195c9460165c34',
// No trailing slash
SERVER_URL: `https://node1-euw6.gcp.devnet.verida.tech`,
// Private key for a Verida identity that is used for interacting with nodes
// Note: Ensure this private key has committed its DID to the network
// Run `yarn run test test/vda-did` to generate a new private key with a valid DID in `verida-js/vda-did`
VDA_PRIVATE_KEY: '',
CONTEXT_NAME: 'Verida Storage Node Test: Test Application 1',
DATABASE_SERVER: 'https://sn-acacia1.tn.verida.tech/', // http://localhost:5000/ for local testing when running local @verida/storage-node
MESSAGE_SERVER: 'https://sn-acacia1.tn.verida.tech/', // http://localhost:5000/ for local testing when running local @verida/storage-node
DATABASE_SERVER: 'http://localhost:5000/', // http://localhost:5000/ for local testing when running local @verida/storage-node
MESSAGE_SERVER: 'http://localhost:5000/', // http://localhost:5000/ for local testing when running local @verida/storage-node
DEFAULT_ENDPOINTS: {
defaultDatabaseServer: {
type: 'VeridaDatabase',
endpointUri: 'https://sn-acacia1.tn.verida.tech/'
endpointUri: 'https://node1-euw6.gcp.devnet.verida.tech'
},
defaultMessageServer: {
type: 'VeridaMessage',
endpointUri: 'https://sn-acacia1.tn.verida.tech/'
endpointUri: 'https://node1-euw6.gcp.devnet.verida.tech'
},
},
TEST_DEVICE_ID: 'Unit test device'
Expand Down
32 changes: 20 additions & 12 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@ let refreshToken, accessToken, newRefreshToken
describe("Server tests", function() {
this.beforeAll(async () => {
//await AuthManager.initDb() -- This is required if the server is running locally and has never been run before, run just once
//await TestUtils.ensureVeridaAccount(CONFIG.VDA_PRIVATE_KEY) -- This is required if the private key has never been initilaized with an application context, run just once
await TestUtils.ensureVeridaAccount(CONFIG.VDA_PRIVATE_KEY) // -- This is required if the private key has never been initilaized with an application context, run just once
accountInfo = await TestUtils.connectAccount(CONFIG.VDA_PRIVATE_KEY)
})

describe("Authenticate", () => {
it("Generates AuthJWT", async () => {
const authJwtResult = await Axios.post(`${SERVER_URL}/auth/generateAuthJwt`, {
did: accountInfo.did,
contextName: CONTEXT_NAME
});
try {
const authJwtResult = await Axios.post(`${SERVER_URL}/auth/generateAuthJwt`, {
did: accountInfo.did,
contextName: CONTEXT_NAME
});

assert.ok(authJwtResult && authJwtResult.data && authJwtResult.data.authJwt, "Have authJWT in response")
assert.ok(authJwtResult && authJwtResult.data && authJwtResult.data.authJwt, "Have authJWT in response")

authRequestId = authJwtResult.data.authJwt.authRequestId
authJwt = authJwtResult.data.authJwt.authJwt
authRequestId = authJwtResult.data.authJwt.authRequestId
authJwt = authJwtResult.data.authJwt.authJwt
} catch (err) {
console.log(err.response.data)
assert.fail(err.message)
}
})

// If running the tests against a remote server with a different access token JWT private key, this test will fail
Expand Down Expand Up @@ -63,8 +68,11 @@ describe("Server tests", function() {

// Also returns a valid access token
assert.ok(authenticateResponse.data.accessToken, "Has an access token")
const validAccessToken = AuthManager.verifyAccessToken(authenticateResponse.data.accessToken)
assert.ok(validAccessToken, "Have a valid access token")

if (authenticateResponse.data.host.match('localhost')) {
const validAccessToken = AuthManager.verifyAccessToken(authenticateResponse.data.accessToken)
assert.ok(validAccessToken, "Have a valid access token")
}
})

it("Verifies refresh tokens", async () => {
Expand Down Expand Up @@ -159,7 +167,7 @@ describe("Server tests", function() {
}

resolve(false)
})
})
})

const connectResult = await pendingConnect
Expand Down Expand Up @@ -333,7 +341,7 @@ describe("Server tests", function() {
assert.ok(response.data.results.indexOf('DeleteAll_1') >= 0, 'Deleted correct databases (DeleteAll_1)')
assert.ok(response.data.results.indexOf('DeleteAll_2') >= 0, 'Deleted correct databases (DeleteAll_2)')
assert.ok(response.data.results.indexOf('DeleteAll_3') >= 0, 'Deleted correct databases (DeleteAll_3)')
assert.ok(TestUtils.verifySignature(response), 'Have a valid signature in response')
assert.ok(TestUtils.verifySignature(response), 'Have a valid signature in response')
})
})

Expand Down
7 changes: 7 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dotenv.config();
const VDA_PRIVATE_KEY = process.env.VDA_PRIVATE_KEY
const wallet = new ethers.Wallet(VDA_PRIVATE_KEY)
const VDA_PUBLIC_KEY = wallet.publicKey
const SERVER_URL = CONFIG.SERVER_URL

class Utils {

Expand Down Expand Up @@ -145,6 +146,12 @@ class Utils {
if (!response.data.signature) {
return false
}

// Skip signature verification if running on localhost
// (local private key is different from the remote private key)
if (!SERVER_URL.match('localhost')) {
return true
}

const signature = response.data.signature
delete response.data['signature']
Expand Down

0 comments on commit b9316e2

Please sign in to comment.