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
|
package suites
import (
"context"
"fmt"
"log"
"strings"
"time"
)
// MultiCookieDomainScenario represents a set of tests for multi cookie domain suite.
type MultiCookieDomainScenario struct {
*RodSuite
domain, nextDomain string
cookieNames []string
remember bool
}
// NewMultiCookieDomainScenario returns a new Multi Cookie Domain Test Scenario.
func NewMultiCookieDomainScenario(domain, nextDomain string, cookieNames []string, remember bool) *MultiCookieDomainScenario {
return &MultiCookieDomainScenario{
RodSuite: NewRodSuite(""),
domain: domain,
nextDomain: nextDomain,
cookieNames: cookieNames,
remember: remember,
}
}
func (s *MultiCookieDomainScenario) SetupSuite() {
browser, err := NewRodSession(RodSessionWithCredentials(s))
if err != nil {
log.Fatal(err)
}
s.RodSession = browser
s.Require().NoError(updateDevEnvFileForDomain(s.domain, false))
}
func (s *MultiCookieDomainScenario) TearDownSuite() {
err := s.RodSession.Stop()
if err != nil {
log.Fatal(err)
}
}
func (s *MultiCookieDomainScenario) SetupTest() {
s.Page = s.doCreateTab(s.T(), HomeBaseURL)
s.verifyIsHome(s.T(), s.Page)
}
func (s *MultiCookieDomainScenario) TearDownTest() {
s.collectCoverage(s.Page)
s.MustClose()
}
func (s *MultiCookieDomainScenario) TestCookieName() {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer func() {
cancel()
s.collectScreenshot(ctx.Err(), s.Page)
}()
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", s.remember, s.domain, "")
s.WaitElementLocatedByID(s.T(), s.Context(ctx), "logout-button")
cookieNames := s.GetCookieNames()
s.Assert().Equalf(s.cookieNames, cookieNames, "cookie names should include '%s' (only and all of) but includes '%s'", strings.Join(s.cookieNames, ","), strings.Join(cookieNames, ","))
}
func (s *MultiCookieDomainScenario) TestRememberMe() {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer func() {
cancel()
s.collectScreenshot(ctx.Err(), s.Page)
}()
s.doVisitLoginPage(s.T(), s.Page, s.domain, "")
s.WaitElementLocatedByID(s.T(), s.Context(ctx), "username-textfield")
has := s.CheckElementExistsLocatedByID(s.T(), s.Context(ctx), "remember-checkbox")
s.Assert().Equal(s.remember, has)
}
func (s *MultiCookieDomainScenario) TestShouldAuthorizeSecret() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer func() {
cancel()
s.collectScreenshot(ctx.Err(), s.Page)
}()
targetURL := fmt.Sprintf("%s/secret.html", SingleFactorBaseURLFmt(s.domain))
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", s.remember, s.domain, targetURL)
s.verifySecretAuthorized(s.T(), s.Page)
}
func (s *MultiCookieDomainScenario) TestShouldRequestLoginOnNextDomainAfterLoginOnFirstDomain() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer func() {
cancel()
s.collectScreenshot(ctx.Err(), s.Page)
}()
firstDomainTargetURL := fmt.Sprintf("%s/secret.html", SingleFactorBaseURLFmt(s.domain))
nextDomainTargetURL := fmt.Sprintf("%s/secret.html", SingleFactorBaseURLFmt(s.nextDomain))
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", s.remember, s.domain, firstDomainTargetURL)
s.verifySecretAuthorized(s.T(), s.Page)
s.doVisit(s.T(), s.Page, nextDomainTargetURL)
s.verifyIsFirstFactorPage(s.T(), s.Page)
}
func (s *MultiCookieDomainScenario) TestShouldStayLoggedInOnNextDomainWhenLoggedOffOnFirstDomain() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer func() {
cancel()
s.collectScreenshot(ctx.Err(), s.Page)
}()
firstDomainTargetURL := fmt.Sprintf("%s/secret.html", SingleFactorBaseURLFmt(s.domain))
nextDomainTargetURL := fmt.Sprintf("%s/secret.html", SingleFactorBaseURLFmt(s.nextDomain))
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", s.remember, s.domain, firstDomainTargetURL)
s.verifySecretAuthorized(s.T(), s.Page)
s.Require().NoError(updateDevEnvFileForDomain(s.nextDomain, false))
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", !s.remember, s.nextDomain, nextDomainTargetURL)
s.verifySecretAuthorized(s.T(), s.Page)
s.doVisit(s.T(), s.Page, fmt.Sprintf("%s%s", GetLoginBaseURL(s.domain), "/logout"))
s.verifyIsFirstFactorPage(s.T(), s.Page)
s.doVisit(s.T(), s.Page, nextDomainTargetURL)
s.verifySecretAuthorized(s.T(), s.Page)
}
|