-
Notifications
You must be signed in to change notification settings - Fork 0
/
keycloak.cy.js
80 lines (73 loc) · 2.73 KB
/
keycloak.cy.js
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
describe('keycloak', () => {
const user = 'myuser'
const auth_password ='testme1234'
it('passes', () => {
cy.visit('http://localhost:8081/')
cy.get('#login').click()
cy.origin(
"http://localhost:8080",
{ args: { user, auth_password } },
({ user, auth_password }) => {
cy.get("#username")
.type(user)
.get("#password")
.type(auth_password);
cy.get("#kc-login").click();
}
);
// should redirect with a valid code in the url
cy.get('#app-details').contains('Welcome to my app')
})
it('passes 2', () => {
cy.visit('https://www.keycloak.org/app/#url=http://localhost:8080&realm=myrealm&client=myclient')
cy.get('#login').click()
cy.origin(
"http://localhost:8080",
{ args: { user, auth_password } },
({ user, auth_password }) => {
cy.get("#username")
.type(user)
.get("#password")
.type(auth_password);
cy.get("#kc-login").click();
}
);
// should redirect with a valid code in the url
cy.get('#user-details').contains('myuser')
})
it('passes 3', () => {
cy.visit('https://www.keycloak.org/app/#url=http://localhost:8080&realm=myrealm&client=myclient')
cy.window().then((win) => {
win.location.href = 'http://localhost:8080/realms/myrealm/protocol/openid-connect/auth?client_id=myclient&redirect_uri=http%3A%2F%2Flocalhost%3A8081%2F%23url%3Dhttp%3A%2F%2Flocalhost%3A8080%26realm%3Dmyrealm%26client%3Dmyclient&state=95fc5616-4e00-4914-8225-8dd2dd7d8a1a&response_mode=fragment&response_type=code&scope=openid&nonce=afca4942-441b-48c6-9145-5f4a146946cd'
})
cy.origin(
"http://localhost:8080",
{ args: { user, auth_password } },
({ user, auth_password }) => {
cy.get("#username")
.type(user)
.get("#password")
.type(auth_password);
cy.get("#kc-login").click();
}
);
})
it('fails on 301 redirect', () => {
cy.intercept('GET', '/stubbed-site', (req) => {
// statusCode defaults to `302`
req.redirect('http://localhost:8080/realms/myrealm/protocol/openid-connect/auth?client_id=myclient&redirect_uri=http%3A%2F%2Flocalhost%3A8081%2F%23url%3Dhttp%3A%2F%2Flocalhost%3A8080%26realm%3Dmyrealm%26client%3Dmyclient&state=95fc5616-4e00-4914-8225-8dd2dd7d8a1a&response_mode=fragment&response_type=code&scope=openid&nonce=afca4942-441b-48c6-9145-5f4a146946cd', 301)
})
cy.visit('/stubbed-site')
cy.origin(
"http://localhost:8080",
{ args: { user, auth_password } },
({ user, auth_password }) => {
cy.get("#username")
.type(user)
.get("#password")
.type(auth_password);
cy.get("#kc-login").click();
}
);
})
})