diff --git a/apier/v1/sessionsv1_it_test.go b/apier/v1/sessionsv1_it_test.go index 6fcc324d9..3d69432f8 100644 --- a/apier/v1/sessionsv1_it_test.go +++ b/apier/v1/sessionsv1_it_test.go @@ -207,12 +207,7 @@ func testSSv1ItAuth(t *testing.T) { if err := sSv1BiRpc.Call(utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { t.Fatal(err) } - // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min - // and in case of postpaid and rated we expect -1 - if ((sSV1RequestType == utils.META_PREPAID || - sSV1RequestType == utils.META_PSEUDOPREPAID) && *rply.MaxUsage != authUsage) || - ((sSV1RequestType == utils.META_POSTPAID || - sSV1RequestType == utils.META_RATED) && *rply.MaxUsage != -1) { + if *rply.MaxUsage != authUsage { t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) } if *rply.ResourceAllocation == "" { @@ -296,10 +291,7 @@ func testSSv1ItAuthWithDigest(t *testing.T) { } // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min // and in case of postpaid and rated we expect -1 - if ((sSV1RequestType == utils.META_PREPAID || - sSV1RequestType == utils.META_PSEUDOPREPAID) && *rply.MaxUsage != authUsage.Seconds()) || - ((sSV1RequestType == utils.META_POSTPAID || - sSV1RequestType == utils.META_RATED) && *rply.MaxUsage != -1) { + if *rply.MaxUsage != authUsage.Seconds() { t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) } if *rply.ResourceAllocation == "" { diff --git a/sessions/sessions.go b/sessions/sessions.go index 5f05e9374..5c4fd265b 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -1290,7 +1290,9 @@ func (sS *SessionS) initSessionDebitLoops(s *Session) { // authSession calculates maximum usage allowed for given session func (sS *SessionS) authSession(tnt string, evStart *engine.SafEvent) (maxUsage time.Duration, err error) { cgrID := GetSetCGRID(evStart) - if _, err = evStart.GetDuration(utils.Usage); err != nil { + var eventUsage time.Duration + eventUsage, err = evStart.GetDuration(utils.Usage) + if err != nil { if err != utils.ErrNotFound { return } @@ -1330,15 +1332,15 @@ func (sS *SessionS) authSession(tnt string, evStart *engine.SafEvent) (maxUsage var rplyMaxUsage time.Duration if !utils.IsSliceMember(prepaidReqs, sr.Event.GetStringIgnoreErrors(utils.RequestType)) { - rplyMaxUsage = time.Duration(-1) + rplyMaxUsage = eventUsage } else if err = sS.ralS.Call(utils.ResponderGetMaxSessionTime, &engine.CallDescriptorWithArgDispatcher{CallDescriptor: sr.CD, ArgDispatcher: s.ArgDispatcher}, &rplyMaxUsage); err != nil { return } if !maxUsageSet || - maxUsage == time.Duration(-1) || - (rplyMaxUsage < maxUsage && rplyMaxUsage != time.Duration(-1)) { + maxUsage == eventUsage || + (rplyMaxUsage < maxUsage && rplyMaxUsage != eventUsage) { maxUsage = rplyMaxUsage maxUsageSet = true }