Repository: codenotary/immudb (language: go)

Issue:
openSession method does not lower the databaseName.
<!-- Please use this template while reporting a bug and provide as much info as possible. 
If applicable, add shell logs or screenshots to help explain your problem.
Thanks! -->

**What happened**
I'm currently using the SDK immudb4j. 
I tried to open a session (defaultdb, immudb, immudb).
Then create a new database.
Close the session.
And open a new one with the new DB.

----------------------------------------------------------------------------------

immuClient.openSession("defaultdb", "immudb", "immudb");

immuClient.createDatabase("hG82t45Plm", true);

immuClient.closeSession();

immuClient.openSession("hG82t45Plm", "immudb", "immudb");

**Database name are case sensitive or more precisely the are  create in lowercase**
**The createDatabase method lower the string "hG82t45Plm"**
**But the openSession method does not**
**So there is an Exception : _UNKNOWN: database does not exist_**

----------------------------------------------------------------------------------

**What you expected to happen**

I do not really know if it is a bug or not  but we can expect the method openSession, as the createDatabase, lower the Database name field.

**How to reproduce it (as minimally and precisely as possible)**

**Environment**
```shell
# run "immu* [v1.4.1]" and copy/paste the output here
```

**Additional info (any other context about the problem)**



Discussion / hints:
thanks a lot for reporting it @HugoLePoisson 
Let me try to fix it
Can you help me @jeroiraz for figuring out where `createDatabase` lower their name?

https://github.com/codenotary/immudb/blob/4b1d3b1c7bcbf5b34425ea1e0b4bd47d6051c5c4/cmd/immuclient/immuc/setcommands.go#L268?

Or just I lower the string directly in https://github.com/codenotary/immudb/blob/4b1d3b1c7bcbf5b34425ea1e0b4bd47d6051c5c4/test/document_storage_tests/documents_tests/actions/session.go#L28 ?
> Can you help me @jeroiraz for figuring out where `createDatabase` lower their name?
> 
> https://github.com/codenotary/immudb/blob/4b1d3b1c7bcbf5b34425ea1e0b4bd47d6051c5c4/cmd/immuclient/immuc/setcommands.go#L268
> 
> ?
> Or just I lower the string directly in
> 
> https://github.com/codenotary/immudb/blob/4b1d3b1c7bcbf5b34425ea1e0b4bd47d6051c5c4/test/document_storage_tests/documents_tests/actions/session.go#L28
> 
> ?

thanks @rubiagatra

The fix may need to be done In server package:
https://github.com/codenotary/immudb/blob/4b1d3b1c7bcbf5b34425ea1e0b4bd47d6051c5c4/pkg/server/session.go#L31

After checking the request is not `nil`, the database name attribute may be force to lower case...

Fix patch:
diff --git a/pkg/server/session.go b/pkg/server/session.go
index b95eebcdd4..3d15015baa 100644
--- a/pkg/server/session.go
+++ b/pkg/server/session.go
@@ -18,6 +18,7 @@ package server
 
 import (
 	"context"
+	"strings"
 
 	"github.com/codenotary/immudb/pkg/api/schema"
 	"github.com/codenotary/immudb/pkg/auth"
@@ -32,6 +33,8 @@ func (s *ImmuServer) OpenSession(ctx context.Context, r *schema.OpenSessionReque
 	if r == nil {
 		return nil, ErrIllegalArguments
 	}
+
+	databaseName := strings.ToLower(r.DatabaseName)
 	if !s.Options.auth {
 		return nil, errors.New(ErrAuthDisabled).WithCode(errors.CodProtocolViolation)
 	}
@@ -49,17 +52,17 @@ func (s *ImmuServer) OpenSession(ctx context.Context, r *schema.OpenSessionReque
 	}
 
 	db := s.sysDB
-	if r.DatabaseName != SystemDBName {
-		db, err = s.dbList.GetByName(r.DatabaseName)
+	if databaseName != SystemDBName {
+		db, err = s.dbList.GetByName(databaseName)
 		if err != nil {
 			return nil, err
 		}
 	}
 
 	if (!u.IsSysAdmin) &&
-		(!u.HasPermission(r.DatabaseName, auth.PermissionAdmin)) &&
-		(!u.HasPermission(r.DatabaseName, auth.PermissionR)) &&
-		(!u.HasPermission(r.DatabaseName, auth.PermissionRW)) {
+		(!u.HasPermission(databaseName, auth.PermissionAdmin)) &&
+		(!u.HasPermission(databaseName, auth.PermissionR)) &&
+		(!u.HasPermission(databaseName, auth.PermissionRW)) {
 		return nil, status.Errorf(codes.PermissionDenied, "Logged in user does not have permission on this database")
 	}
 


Test patch:
diff --git a/pkg/integration/session_test.go b/pkg/integration/session_test.go
index 63e3c574df..9e72e88516 100644
--- a/pkg/integration/session_test.go
+++ b/pkg/integration/session_test.go
@@ -63,6 +63,15 @@ func TestSession_OpenCloseSession(t *testing.T) {
 
 	err = client.CloseSession(context.Background())
 	require.NoError(t, err)
+
+	t.Run("Lowercase Database Name", func(t *testing.T) {
+		err = client.OpenSession(context.Background(), []byte(`immudb`), []byte(`immudb`), "DeFaulTDb")
+		require.NoError(t, err)
+
+		err = client.CloseSession(context.Background())
+		require.NoError(t, err)
+
+	})
 }
 
 func TestSession_OpenCloseSessionMulti(t *testing.T) {