This repository was archived by the owner on May 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed
internal/server/api/shared Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -34,12 +34,16 @@ func (m *Middleware) IsLicenseExpired() gin.HandlerFunc {
3434 return
3535 }
3636
37+ if lic .IsOSS () {
38+ return
39+ }
40+
3741 if lic .IsOverLimit () {
3842 gb .AbortWithErrorResponse (c , http .StatusPaymentRequired , "The member count is over the limit." )
3943 return
4044 }
4145
42- if ! lic .IsTrial () && lic .IsExpired () {
46+ if lic .IsStandard () && lic .IsExpired () {
4347 now := time .Now ()
4448 if lic .ExpiredAt .Add (extraDuration ).Before (now ) {
4549 gb .AbortWithErrorResponse (c , http .StatusPaymentRequired , "The license is expired." )
Original file line number Diff line number Diff line change @@ -15,6 +15,33 @@ import (
1515func TestMiddleware_IsLicenseExpired (t * testing.T ) {
1616 month := 30 * 24 * time .Hour
1717
18+ t .Run ("Return 200 when the license is OSS." , func (t * testing.T ) {
19+ ctrl := gomock .NewController (t )
20+ m := mock .NewMockInteractor (ctrl )
21+
22+ m .
23+ EXPECT ().
24+ GetLicense (gomock .Any ()).
25+ Return (vo .NewOSSLicense (), nil )
26+
27+ gin .SetMode (gin .ReleaseMode )
28+ router := gin .New ()
29+
30+ lm := NewMiddleware (m )
31+ router .GET ("/repos" , lm .IsLicenseExpired (), func (c * gin.Context ) {
32+ c .Status (http .StatusOK )
33+ })
34+
35+ req , _ := http .NewRequest ("GET" , "/repos" , nil )
36+ w := httptest .NewRecorder ()
37+
38+ router .ServeHTTP (w , req )
39+
40+ if w .Code != http .StatusOK {
41+ t .Fatalf ("IsLicenseExpired = %v, wanted %v" , w .Code , http .StatusOK )
42+ }
43+ })
44+
1845 t .Run ("Return 402 error when the count of member is over the limit." , func (t * testing.T ) {
1946 ctrl := gomock .NewController (t )
2047 m := mock .NewMockInteractor (ctrl )
Original file line number Diff line number Diff line change 77)
88
99const (
10- LicenseKindTrial LicenseKind = "trial"
10+ // LicenseKindOSS is a license for the community edition.
11+ LicenseKindOSS LicenseKind = "oss"
12+ // LicenseKindTrial is a trial license of the enterprise edition.
13+ LicenseKindTrial LicenseKind = "trial"
14+ // LicenseKindStandard is a license of the enterprise edition.
1115 LicenseKindStandard LicenseKind = "standard"
1216)
1317
@@ -28,6 +32,13 @@ type (
2832 }
2933)
3034
35+ func NewOSSLicense () * License {
36+ return & License {
37+ Kind : LicenseKindOSS ,
38+ MemberCount : - 1 ,
39+ }
40+ }
41+
3142func NewTrialLicense (cnt int ) * License {
3243 return & License {
3344 Kind : LicenseKindTrial ,
@@ -45,14 +56,24 @@ func NewStandardLicense(cnt int, d *SigningData) *License {
4556 }
4657}
4758
59+ func (l * License ) IsOSS () bool {
60+ return l .Kind == LicenseKindOSS
61+ }
62+
4863func (l * License ) IsTrial () bool {
4964 return l .Kind == LicenseKindTrial
5065}
5166
67+ func (l * License ) IsStandard () bool {
68+ return l .Kind == LicenseKindStandard
69+ }
70+
71+ // IsOverLimit verify it is over the limit of the license.
5272func (l * License ) IsOverLimit () bool {
5373 return l .MemberCount > l .MemberLimit
5474}
5575
76+ // IsExpired verify that the license is expired or not.
5677func (l * License ) IsExpired () bool {
5778 return l .ExpiredAt .Before (time .Now ())
5879}
You can’t perform that action at this time.
0 commit comments