15768: selections persist through sort/refresh, not filter Arvados-DCO-1.1-Signed...
[arvados-workbench2.git] / src / validators / is-rsa-key.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { isRsaKey } from './is-rsa-key';
6
7 describe('rsa-key-validator', () => {
8     const rsaKey = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDPpavAS1wUq2+j7PgwkDS+9lm43AkdGxZo+T8qm6ZcB009EUEXya3lQolA52gg/i5aGZg4LT3t1OKxbsaClMd7sNZXYrMW9vd/utvGgAlNEbE/yXsEl2kpxt8lz7RI1XLnoWcV+aKyrsiKdrMKnZyG8CBxKdtzxHzWRl4N1BGrFJf/RnUWJv2VvM/h4/O+KXIjFokPkJ1F8yQChp5OKGkBKGXQ1vV4LjXqEXGVlgiQFM4U2NvCA8hXQR8mYm1vOsTYJzoSsnb+ewbXlVH5d7XsR5S2ULOr88vuYN/P4DF/Q3pEBi7BOyee61P3eHvhCNtb+jQMt59Vj/96y5C/reTMRo2R3B4bmX+Zxr3+DCC5tO1y+U5V39fu7cweimKXc78QDGGAVN0kz4P6P137b5WkCYIozeiBvWRsbGIlHjlGu9+0WuotdluD+OrTguuZ2zr8f32ijddO6y0J+aIdmTxQPxtmcQuRtpRfquoJGLhWAJH6mNZKbWkqqVfd5BA0TYs=';
9     const badKey = 'ssh-rsa bad'
10
11     const ERROR_MESSAGE = 'Public key is invalid';
12
13     describe('rsaKeyValidation', () => {
14         it('should accept keys with comment', () => {
15             // then
16             expect(isRsaKey(rsaKey + " firstlast@example.com")).toBeUndefined();
17         });
18
19         it('should accept keys without comment', () => {
20             // then
21             expect(isRsaKey(rsaKey)).toBeUndefined();
22         });
23
24         it('should reject keys with trailing whitespace', () => {
25             // then
26             expect(isRsaKey(rsaKey + " ")).toBe(ERROR_MESSAGE);
27             expect(isRsaKey(rsaKey + "\n")).toBe(ERROR_MESSAGE);
28             expect(isRsaKey(rsaKey + "\r\n")).toBe(ERROR_MESSAGE);
29             expect(isRsaKey(rsaKey + "\t")).toBe(ERROR_MESSAGE);
30         });
31
32         it('should reject invalid keys', () => {
33             // then
34             expect(isRsaKey(badKey)).toBe(ERROR_MESSAGE);
35         });
36
37     });
38
39 });