-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NC | NSFS | IAM | Tech Debts (IAM Integration Tests, Username Validat…
…ion Move module and Allow IAM User to Create Bucket) 1. IAM Integration Tests: add the file test_nc_iam_basic_integration.js and make the needed changes in the fiiles nc_coretest.js (add the IAM port), nc_index (add the new test in the CI) and test_utils.js (add the IAM client - like we have S3 client) - the IAM integration tests the APIs of IAM that we support today. 2. Username Validation Move the Module: we have 2 flows noobaa-cli and API (S3, IAM), and don't want to import modules between the flows and only from an above level. Therefore, I moved the function validate_username from the iam_utils to validation_utils, since it used other functions I also had to move them and move the testing file. 3. Allow IAM Users to Create Bucket - we temporarily didn't allow IAM users to create buckets. Signed-off-by: shirady <[email protected]>
- Loading branch information
Showing
12 changed files
with
684 additions
and
330 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
138 changes: 138 additions & 0 deletions
138
src/test/unit_tests/jest_tests/test_validation_utils.test.js
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,138 @@ | ||
/* Copyright (C) 2024 NooBaa */ | ||
/* eslint-disable max-lines-per-function */ | ||
'use strict'; | ||
const validation_utils = require('../../../util/validation_utils'); | ||
const iam_constants = require('../../../endpoint/iam/iam_constants'); | ||
const RpcError = require('../../../rpc/rpc_error'); | ||
|
||
class NoErrorThrownError extends Error {} | ||
|
||
describe('validate_user_input', () => { | ||
const RPC_CODE_VALIDATION_ERROR = 'VALIDATION_ERROR'; | ||
describe('validate_username', () => { | ||
const min_length = 1; | ||
const max_length = 64; | ||
it('should return true when username is undefined', () => { | ||
let dummy_username; | ||
const res = validation_utils.validate_username(dummy_username, iam_constants.IAM_PARAMETER_NAME.USERNAME); | ||
expect(res).toBeUndefined(); | ||
}); | ||
|
||
it('should return true when username is at the min or max length', () => { | ||
expect(validation_utils.validate_username('a', iam_constants.IAM_PARAMETER_NAME.USERNAME)).toBe(true); | ||
expect(validation_utils.validate_username('a'.repeat(max_length), iam_constants.IAM_PARAMETER_NAME.USERNAME)).toBe(true); | ||
}); | ||
|
||
it('should return true when username is within the length constraint', () => { | ||
expect(validation_utils.validate_username('a'.repeat(min_length + 1), iam_constants.IAM_PARAMETER_NAME.USERNAME)).toBe(true); | ||
expect(validation_utils.validate_username('a'.repeat(max_length - 1), iam_constants.IAM_PARAMETER_NAME.USERNAME)).toBe(true); | ||
}); | ||
|
||
it('should return true when username is valid', () => { | ||
const dummy_username = 'Robert'; | ||
const res = validation_utils.validate_username(dummy_username, iam_constants.IAM_PARAMETER_NAME.USERNAME); | ||
expect(res).toBe(true); | ||
}); | ||
|
||
it('should throw error when username is invalid - contains invalid character', () => { | ||
try { | ||
validation_utils.validate_username('{}', iam_constants.IAM_PARAMETER_NAME.USERNAME); | ||
throw new NoErrorThrownError(); | ||
} catch (err) { | ||
expect(err).toBeInstanceOf(RpcError); | ||
expect(err.rpc_code).toBe(RPC_CODE_VALIDATION_ERROR); | ||
} | ||
}); | ||
|
||
|
||
it('should throw error when username is invalid - internal limitation (anonymous)', () => { | ||
try { | ||
validation_utils.validate_username('anonymous', iam_constants.IAM_PARAMETER_NAME.USERNAME); | ||
throw new NoErrorThrownError(); | ||
} catch (err) { | ||
expect(err).toBeInstanceOf(RpcError); | ||
expect(err.rpc_code).toBe(RPC_CODE_VALIDATION_ERROR); | ||
} | ||
}); | ||
|
||
it('should throw error when username is invalid - internal limitation (with leading or trailing spaces)', () => { | ||
try { | ||
validation_utils.validate_username(' name-with-spaces ', iam_constants.IAM_PARAMETER_NAME.USERNAME); | ||
throw new NoErrorThrownError(); | ||
} catch (err) { | ||
expect(err).toBeInstanceOf(RpcError); | ||
expect(err.rpc_code).toBe(RPC_CODE_VALIDATION_ERROR); | ||
} | ||
}); | ||
|
||
it('should throw error when username is too short', () => { | ||
try { | ||
const dummy_username = ''; | ||
validation_utils.validate_username(dummy_username, iam_constants.IAM_PARAMETER_NAME.USERNAME); | ||
throw new NoErrorThrownError(); | ||
} catch (err) { | ||
expect(err).toBeInstanceOf(RpcError); | ||
expect(err.rpc_code).toBe(RPC_CODE_VALIDATION_ERROR); | ||
} | ||
}); | ||
|
||
it('should throw error when username is too long', () => { | ||
try { | ||
const dummy_username = 'A'.repeat(max_length + 1); | ||
validation_utils.validate_username(dummy_username, iam_constants.IAM_PARAMETER_NAME.USERNAME); | ||
throw new NoErrorThrownError(); | ||
} catch (err) { | ||
expect(err).toBeInstanceOf(RpcError); | ||
expect(err.rpc_code).toBe(RPC_CODE_VALIDATION_ERROR); | ||
} | ||
}); | ||
|
||
it('should throw error for invalid input types (null)', () => { | ||
try { | ||
// @ts-ignore | ||
const invalid_username = null; | ||
validation_utils.validate_username(invalid_username, iam_constants.IAM_PARAMETER_NAME.USERNAME); | ||
throw new NoErrorThrownError(); | ||
} catch (err) { | ||
expect(err).toBeInstanceOf(RpcError); | ||
expect(err.rpc_code).toBe(RPC_CODE_VALIDATION_ERROR); | ||
} | ||
}); | ||
|
||
it('should throw error for invalid input types (number)', () => { | ||
try { | ||
const invalid_username = 1; | ||
// @ts-ignore | ||
validation_utils.validate_username(invalid_username, iam_constants.IAM_PARAMETER_NAME.USERNAME); | ||
throw new NoErrorThrownError(); | ||
} catch (err) { | ||
expect(err).toBeInstanceOf(RpcError); | ||
expect(err.rpc_code).toBe(RPC_CODE_VALIDATION_ERROR); | ||
} | ||
}); | ||
|
||
it('should throw error for invalid input types (object)', () => { | ||
try { | ||
const invalid_username = {}; | ||
// @ts-ignore | ||
validation_utils.validate_username(invalid_username, iam_constants.IAM_PARAMETER_NAME.USERNAME); | ||
throw new NoErrorThrownError(); | ||
} catch (err) { | ||
expect(err).toBeInstanceOf(RpcError); | ||
expect(err.rpc_code).toBe(RPC_CODE_VALIDATION_ERROR); | ||
} | ||
}); | ||
|
||
it('should throw error for invalid input types (boolean)', () => { | ||
try { | ||
const invalid_username = false; | ||
// @ts-ignore | ||
validation_utils.validate_username(invalid_username, iam_constants.IAM_PARAMETER_NAME.USERNAME); | ||
throw new NoErrorThrownError(); | ||
} catch (err) { | ||
expect(err).toBeInstanceOf(RpcError); | ||
expect(err.rpc_code).toBe(RPC_CODE_VALIDATION_ERROR); | ||
} | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.