-
Notifications
You must be signed in to change notification settings - Fork 8.2k
/
get_current.ts
145 lines (135 loc) · 4.79 KB
/
get_current.ts
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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { parse as parseCookie } from 'tough-cookie';
import { expect } from 'expect';
import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService }: FtrProviderContext) {
const supertestWithoutAuth = getService('supertestWithoutAuth');
const security = getService('security');
describe('Getting user profile for the current user', () => {
const testUserName = 'user_with_profile';
async function login() {
const response = await supertestWithoutAuth
.post('/internal/security/login')
.set('kbn-xsrf', 'xxx')
.send({
providerType: 'basic',
providerName: 'basic',
currentURL: '/',
params: { username: testUserName, password: 'changeme' },
})
.expect(200);
return parseCookie(response.headers['set-cookie'][0])!;
}
before(async () => {
await security.user.create(testUserName, {
password: 'changeme',
roles: [`viewer`],
full_name: 'User With Profile',
email: 'user_with_profile@get_current_test',
});
});
after(async () => {
await security.user.delete(testUserName);
});
it('can get user profile for the current user', async () => {
const sessionCookie = await login();
await supertestWithoutAuth
.post('/internal/security/user_profile/_data')
.set('kbn-xsrf', 'xxx')
.set('Cookie', sessionCookie.cookieString())
.send({ some: 'data', another: 'another-data' })
.expect(200);
const { body: profileWithoutData } = await supertestWithoutAuth
.get('/internal/security/user_profile')
.set('Cookie', sessionCookie.cookieString())
.expect(200);
const { body: profileWithAllData } = await supertestWithoutAuth
.get('/internal/security/user_profile?dataPath=*')
.set('Cookie', sessionCookie.cookieString())
.expect(200);
const { body: profileWithSomeData } = await supertestWithoutAuth
.get('/internal/security/user_profile?dataPath=some')
.set('Cookie', sessionCookie.cookieString())
.expect(200);
const { body: userWithProfileId } = await supertestWithoutAuth
.get('/internal/security/me')
.set('Cookie', sessionCookie.cookieString())
.expect(200);
// Profile UID is supposed to be stable.
expectSnapshot(profileWithoutData).toMatchInline(`
Object {
"data": Object {},
"enabled": true,
"labels": Object {},
"uid": "u_K1WXIRQbRoHiuJylXp842IEhAO_OdqT7SDHrJSzUIjU_0",
"user": Object {
"authentication_provider": Object {
"name": "basic",
"type": "basic",
},
"email": "user_with_profile@get_current_test",
"full_name": "User With Profile",
"realm_name": "default_native",
"roles": Array [
"viewer",
],
"username": "user_with_profile",
},
}
`);
expectSnapshot(profileWithAllData).toMatchInline(`
Object {
"data": Object {
"another": "another-data",
"some": "data",
},
"enabled": true,
"labels": Object {},
"uid": "u_K1WXIRQbRoHiuJylXp842IEhAO_OdqT7SDHrJSzUIjU_0",
"user": Object {
"authentication_provider": Object {
"name": "basic",
"type": "basic",
},
"email": "user_with_profile@get_current_test",
"full_name": "User With Profile",
"realm_name": "default_native",
"roles": Array [
"viewer",
],
"username": "user_with_profile",
},
}
`);
expectSnapshot(profileWithSomeData).toMatchInline(`
Object {
"data": Object {
"some": "data",
},
"enabled": true,
"labels": Object {},
"uid": "u_K1WXIRQbRoHiuJylXp842IEhAO_OdqT7SDHrJSzUIjU_0",
"user": Object {
"authentication_provider": Object {
"name": "basic",
"type": "basic",
},
"email": "user_with_profile@get_current_test",
"full_name": "User With Profile",
"realm_name": "default_native",
"roles": Array [
"viewer",
],
"username": "user_with_profile",
},
}
`);
expect(userWithProfileId.profile_uid).toBe('u_K1WXIRQbRoHiuJylXp842IEhAO_OdqT7SDHrJSzUIjU_0');
});
});
}