-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathbasic-e2e.test.ts
More file actions
179 lines (152 loc) · 7.6 KB
/
Copy pathbasic-e2e.test.ts
File metadata and controls
179 lines (152 loc) · 7.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// import puppeteer from 'puppeteer';
// require('regenerator-runtime/runtime');
// describe('App.js', () => {
// var browser;
// var page;
// const debug = {
// // headless: false,
// // slowMo: 150,
// args: ['--no-sandbox', '--disable-setuid-sandbox'], // needed for docker, we trust the content of opencre.org
// };
// const config = {};
// beforeAll(async () => {
// jest.setTimeout(1000000);
// browser = await puppeteer.launch(debug);
// page = await browser.newPage();
// page.setDefaultTimeout(15000);
// });
// it('contains the welcome text', { url: 'http://localhost:5000' }, async () => {
// await page.goto('http://localhost:5000');
// await page.waitForSelector('#SearchBar');
// const text = await page.$eval('#SearchBar', (e) => e.textContent);
// expect(text).toContain('Search');
// });
// it('can search for random strs', { url: 'http://127.0.0.1:5000' }, async () => {
// await page.goto('http://127.0.0.1:5000');
// await page.waitForSelector('#SearchBar');
// await page.type('#SearchBar > div > input', 'asdf');
// await page.click('#SearchBar > div > button');
// await page.waitForSelector('.content');
// const text = await page.$eval('.content', (e) => e.textContent);
// expect(text).toContain('No results match your search term');
// });
// it(
// 'can search for cryptography using the free text method and it returns both Nodes and CRES',
// { url: 'http://127.0.0.1:5000' },
// async () => {
// await page.goto('http://127.0.0.1:5000');
// await page.waitForSelector('#SearchBar');
// await page.type('#SearchBar > div > input', 'crypto');
// await page.click('#SearchBar > div > button');
// await page.waitForSelector('.content');
// const text = await page.$eval('.content', (e) => e.textContent);
// expect(text).not.toContain('No results match your search term');
// await page.waitForSelector('.standard-page__links-container');
// const results = await page.$$('.standard-page__links-container');
// expect(results.length).toBeGreaterThan(1);
// const cres = await page.$$('.cre-page >div>div>.standard-page__links-container');
// expect(cres.length).toBeGreaterThan(1);
// const docs = await page.$$('.cre-page >div>div:nth-child(2)>.standard-page__links-container');
// expect(docs.length).toBeGreaterThan(1);
// }
// );
// it(
// 'can search for a standard by name, section and the standard page works as expected',
// { url: 'http://127.0.0.1:5000' },
// async () => {
// await page.goto('http://127.0.0.1:5000/node/standard/ASVS');
// await page.waitForSelector('.content');
// const text = await page.$$('.content', (e) => e.textContent);
// expect(text).not.toContain('No results match your search term');
// await page.waitForSelector('.standard-page__links-container');
// // title match
// const page_title = await page.$eval('.standard-page__heading', (e) => e.textContent);
// expect(page_title).toContain('ASVS');
// // results
// const results = await page.$$('.standard-page__links-container');
// expect(results.length).toBeGreaterThan(1);
// // pagination
// const original_content = await page.content();
// await page.click('a[type="pageItem"][value="2"]');
// await page.waitForSelector('.content');
// expect(await page.content()).not.toEqual(original_content);
// // link to section
// await page.click('.standard-page__links-container>.title>a');
// await page.waitForSelector('.content');
// const url = await page.url();
// expect(url).toContain('section');
// const section = await page.$eval('.standard-page > span:nth-child(2)', (e) => e.textContent);
// expect(section).toContain('Reference:');
// // show reference
// const hrefs = await page.evaluate(() =>
// Array.from(document.querySelectorAll('.section-page > a[href]'), (a) => a.getAttribute('href'))
// );
// expect(hrefs[0]).toContain('https://');
// // link to at least one cre
// const cre_links = await page.$$('.cre-page__links-container > .title > a:nth-child(1)');
// expect(cre_links.length).toBeGreaterThan(0);
// const cre_links_hrefs = await page.evaluate(() =>
// Array.from(document.querySelectorAll('.cre-page__links-container > .title > a:nth-child(1)'), (a) =>
// a.getAttribute('href')
// )
// );
// expect(cre_links_hrefs[0]).toContain('/cre/');
// }
// );
// it('can search for a cre', { url: 'http://127.0.0.1:5000' }, async () => {
// await page.goto('http://127.0.0.1:5000');
// await page.waitForSelector('#SearchBar');
// await page.type('#SearchBar > div > input', '558-807');
// await page.click('#SearchBar > div > button');
// await page.waitForSelector('.content');
// const text = await page.$$('.content', (e) => e.textContent);
// expect(text).not.toContain('No results match your search term');
// await page.waitForSelector('.standard-page__links-container');
// // title match
// const entry_title = await page.$eval('div.title.document-node', (e) => e.textContent);
// expect(entry_title).toContain('Mutually authenticate application and credential service provider');
// // results
// const results = await page.$$('.standard-page__links-container');
// expect(results.length).toBe(1);
// // // nesting
// await page.click('.dropdown');
// const selector =
// '.standard-page__links-container>.document-node>.document-node__link-type-container:nth-child(2)';
// await page.waitForSelector(selector);
// const nested = await page.$$(
// '.standard-page__links-container>.document-node>.document-node__link-type-container>div>.accordion'
// );
// expect(nested.length).toBeGreaterThan(1);
// });
// it('can filter', { url: 'http://127.0.0.1:5000' }, async () => {
// await page.goto('http://127.0.0.1:5000/cre/558-807?applyFilters=true&filters=asvs');
// await page.waitForSelector('.cre-page__links-container');
// // Get inner text
// const innerText = await page.evaluate(
// () => (document.querySelector('.cre-page__links-container') as HTMLElement)?.innerText
// );
// expect(innerText).toContain('ASVS');
// expect(innerText).toContain('CRE');
// expect(innerText).not.toContain('NIST');
// // ensure case insensitive filtering
// await page.goto('http://127.0.0.1:5000/cre/558-807?applyFilters=true&filters=ASVS');
// await page.waitForSelector('.cre-page__links-container');
// const intxt = await page.evaluate(
// () => (document.querySelector('.cre-page__links-container') as HTMLElement)?.innerText
// );
// expect(intxt).toContain('ASVS');
// expect(intxt).toContain('CRE');
// expect(intxt).not.toContain('NIST');
// const clearFilters = await page.evaluate(
// () => (document.querySelector('#clearFilterButton') as HTMLElement)?.innerText
// );
// expect(clearFilters).toContain('Clear Filters');
// });
// it('can smartlink', { url: 'http://127.0.0.1:5000' }, async () => {
// const response = await page.goto('http://127.0.0.1:5000/smartlink/standard/CWE/1002');
// expect(response.url()).toBe('http://127.0.0.1:5000/node/standard/CWE/sectionid/1002');
// const redirectResponse = await page.goto('http://127.0.0.1:5000/smartlink/standard/CWE/404');
// expect(redirectResponse.url()).toBe('https://cwe.mitre.org/data/definitions/404.html');
// });
// afterAll(async () => await browser.close());
// });