Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: removed all the standalone test case #13

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6191901
refactor: isPlugin for API level
Rajat-Dabade Jun 27, 2024
fae82fe
chore: removed GetContextConn as it is not required
Rajat-Dabade Jun 27, 2024
a20079b
chore: clean up api.go removed none required function
Rajat-Dabade Jun 27, 2024
60c76e9
chore: removed commented code
Rajat-Dabade Jun 27, 2024
4c9a8a9
refactor: removed the admin as its no log required
Rajat-Dabade Jun 27, 2024
f942a47
refactor: removed handlePostTeamRegenerateSignupToken as not used any…
Rajat-Dabade Jun 27, 2024
688f53a
refactor: updated make file rules
Rajat-Dabade Jun 28, 2024
80d402e
refactor: removed isGuest code
Rajat-Dabade Jun 28, 2024
403ba9c
refactor: removed auth login password changepassword code
Rajat-Dabade Jun 28, 2024
f2b54b8
chore: linter fixes
Rajat-Dabade Jun 28, 2024
70467de
refactor: removed user login register code
Rajat-Dabade Jun 30, 2024
ef9438a
chore: linter fixes
Rajat-Dabade Jul 1, 2024
2a1a362
refactor: removed auth layer
Rajat-Dabade Jul 1, 2024
e718d7e
refactor: removed isSingle user checks
Rajat-Dabade Jul 1, 2024
084839a
chore: removed debugging logs
Rajat-Dabade Jul 1, 2024
3b46c4b
chore: removed debugging logs
Rajat-Dabade Jul 1, 2024
64af4d5
revert: isGuestUser check
Rajat-Dabade Jul 5, 2024
4735490
Deprecate standalone SQL store level (#4)
Rajat-Dabade Jul 13, 2024
fdeee37
MM-59356: Fixing testcase for webapp and server (#6)
Rajat-Dabade Jul 16, 2024
868136f
refactor: removed all the standalone test case
Rajat-Dabade Jul 16, 2024
4b9bdfc
chore: removed test cases
Rajat-Dabade Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Check-in tests

on:
push:
branches:
- 'main'
- 'releases-**'
pull_request:
workflow_dispatch:

env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
EXCLUDE_ENTERPRISE: true

jobs:
webapp-test:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
path: "focalboard"
- name: npm ci
run: |
cd focalboard/webapp && npm ci

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20.11.0

- name: Lint & test webapp
run: cd focalboard; make webapp-ci

- name: set up golangci-lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.0

- name: Lint & test server
run: cd focalboard; make server-ci
40 changes: 38 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ endif

@echo plugin built at: dist/$(BUNDLE_NAME)

info: ## Display build information
@echo "Build Number: $(BUILD_NUMBER)"
@echo "Build Date: $(BUILD_DATE)"
@echo "Build Hash: $(BUILD_HASH)"
@echo "Plugin ID: $(PLUGIN_ID)"
@echo "Plugin Version: $(PLUGIN_VERSION)"
@echo "Bundle Name: $(BUNDLE_NAME)"

## Builds and bundles the plugin.
.PHONY: dist
dist: apply server webapp bundle
Expand Down Expand Up @@ -357,6 +365,8 @@ generate: ## Install and run code generators.
cd server; go install github.com/golang/mock/[email protected]
cd server; go generate ./...

server-ci: server-lint

server-lint: ## Run linters on server code.
@if ! [ -x "$$(command -v golangci-lint)" ]; then \
echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install-golangci-lint for installation instructions."; \
Expand All @@ -373,7 +383,7 @@ modd-precheck:
webapp-ci: ## Webapp CI: linting & testing.
cd webapp; npm run check
cd webapp; npm run test
cd webapp: npm run check-types
cd webapp; npm run check-types

webapp-test: ## jest tests for webapp
cd webapp; npm run test
Expand All @@ -382,7 +392,33 @@ watch-plugin: modd-precheck ## Run and upload the plugin to a development server
env FOCALBOARD_BUILD_TAGS='$(BUILD_TAGS)' modd -f modd-watchplugin.conf

live-watch-plugin: modd-precheck ## Run and update locally the plugin in the development server
cd mattermost-plugin; make live-watch
make live-watch

server-test: server-test-mysql server-test-postgres

server-test-mysql: export FOCALBOARD_UNIT_TESTING=1
server-test-mysql: export FOCALBOARD_STORE_TEST_DB_TYPE=mysql
server-test-mysql: export FOCALBOARD_STORE_TEST_DOCKER_PORT=44446

server-test-mysql: ## Run server tests using mysql
@echo Starting docker container for mysql
docker-compose -f ./docker-testing/docker-compose-mysql.yml down -v --remove-orphans
docker-compose -f ./docker-testing/docker-compose-mysql.yml run start_dependencies
cd server; go test -tags '$(BUILD_TAGS)' -race -v -coverpkg=./... -coverprofile=server-mysql-profile.coverage -count=1 -timeout=30m ./...
cd server; go tool cover -func server-mysql-profile.coverage
docker-compose -f ./docker-testing/docker-compose-mysql.yml down -v --remove-orphans

server-test-postgres: export FOCALBOARD_UNIT_TESTING=1
server-test-postgres: export FOCALBOARD_STORE_TEST_DB_TYPE=postgres
server-test-postgres: export FOCALBOARD_STORE_TEST_DOCKER_PORT=44447

server-test-postgres: ## Run server tests using postgres
@echo Starting docker container for postgres
docker-compose -f ./docker-testing/docker-compose-postgres.yml down -v --remove-orphans
docker-compose -f ./docker-testing/docker-compose-postgres.yml run start_dependencies
cd server; go test -tags '$(BUILD_TAGS)' -race -v -coverpkg=./... -coverprofile=server-postgres-profile.coverage -count=1 -timeout=30m ./...
cd server; go tool cover -func server-postgres-profile.coverage
docker-compose -f ./docker-testing/docker-compose-postgres.yml down -v --remove-orphans

swagger: ## Generate swagger API spec and clients based on it.
mkdir -p server/swagger/docs
Expand Down
25 changes: 25 additions & 0 deletions docker-testing/docker-compose-mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '2.4'
services:
mysql:
image: "mysql/mysql-server:8.0.32"
restart: always
environment:
MYSQL_ROOT_HOST: "%"
MYSQL_ROOT_PASSWORD: mostest
MYSQL_PASSWORD: mostest
MYSQL_USER: mmuser
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 5s
timeout: 10s
retries: 3
tmpfs: /var/lib/mysql
ports:
- 44446:3306

start_dependencies:
image: mattermost/mattermost-wait-for-dep:latest
depends_on:
- mysql
command: mysql

23 changes: 23 additions & 0 deletions docker-testing/docker-compose-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '2.4'
services:
postgres:
image: "postgres:10"
restart: always
environment:
POSTGRES_USER: mmuser
POSTGRES_PASSWORD: mostest
healthcheck:
test: [ "CMD", "pg_isready", "-h", "localhost" ]
interval: 5s
timeout: 10s
retries: 3
tmpfs: /var/lib/postgresql/data
ports:
- 44447:5432

start_dependencies:
image: mattermost/mattermost-wait-for-dep:latest
depends_on:
- postgres
command: postgres:5432

8 changes: 0 additions & 8 deletions server/admin-scripts/reset-password.sh

This file was deleted.

56 changes: 0 additions & 56 deletions server/api/admin.go

This file was deleted.

34 changes: 10 additions & 24 deletions server/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ var (
// REST APIs

type API struct {
app *app.App
authService string
permissions permissions.PermissionsService
singleUserToken string
MattermostAuth bool
logger mlog.LoggerIFace
audit *audit.Audit
isPlugin bool
app *app.App
authService string
permissions permissions.PermissionsService
logger mlog.LoggerIFace
audit *audit.Audit
}

func NewAPI(
Expand All @@ -51,16 +48,13 @@ func NewAPI(
permissions permissions.PermissionsService,
logger mlog.LoggerIFace,
audit *audit.Audit,
isPlugin bool,
) *API {
return &API{
app: app,
singleUserToken: singleUserToken,
authService: authService,
permissions: permissions,
logger: logger,
audit: audit,
isPlugin: isPlugin,
app: app,
authService: authService,
permissions: permissions,
logger: logger,
audit: audit,
}
}

Expand All @@ -77,7 +71,6 @@ func (a *API) RegisterRoutes(r *mux.Router) {

// V2 routes (ToDo: migrate these to V3 when ready to ship V3)
a.registerUsersRoutes(apiv2)
a.registerAuthRoutes(apiv2)
a.registerMembersRoutes(apiv2)
a.registerCategoriesRoutes(apiv2)
a.registerSharingRoutes(apiv2)
Expand All @@ -104,10 +97,6 @@ func (a *API) RegisterRoutes(r *mux.Router) {
a.registerSystemRoutes(r)
}

func (a *API) RegisterAdminRoutes(r *mux.Router) {
r.HandleFunc("/api/v2/admin/users/{username}/password", a.adminRequired(a.handleAdminSetPassword)).Methods("POST")
}

func getUserID(r *http.Request) string {
ctx := r.Context()
session, ok := ctx.Value(sessionContextKey).(*model.Session)
Expand Down Expand Up @@ -169,9 +158,6 @@ func (a *API) hasValidReadTokenForBoard(r *http.Request, boardID string) bool {
}

func (a *API) userIsGuest(userID string) (bool, error) {
if a.singleUserToken != "" {
return false, nil
}
return a.app.UserIsGuest(userID)
}

Expand Down
1 change: 0 additions & 1 deletion server/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestErrorResponse(t *testing.T) {
// bad request
{"ErrBadRequest", model.NewErrBadRequest("bad field"), http.StatusBadRequest, "bad field"},
{"ErrViewsLimitReached", model.ErrViewsLimitReached, http.StatusBadRequest, "limit reached"},
{"ErrAuthParam", model.NewErrAuthParam("password is required"), http.StatusBadRequest, "password is required"},
{"ErrInvalidCategory", model.NewErrInvalidCategory("open"), http.StatusBadRequest, "open"},
{"ErrBoardMemberIsLastAdmin", model.ErrBoardMemberIsLastAdmin, http.StatusBadRequest, "no admins"},
{"ErrBoardIDMismatch", model.ErrBoardIDMismatch, http.StatusBadRequest, "Board IDs do not match"},
Expand Down
48 changes: 1 addition & 47 deletions server/api/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,51 +204,5 @@ func (a *API) handleArchiveExportTeam(w http.ResponseWriter, r *http.Request) {
// description: internal error
// schema:
// "$ref": "#/definitions/ErrorResponse"
if a.MattermostAuth {
a.errorResponse(w, r, model.NewErrNotImplemented("not permitted in plugin mode"))
return
}

vars := mux.Vars(r)
teamID := vars["teamID"]

ctx := r.Context()
session, _ := ctx.Value(sessionContextKey).(*model.Session)
userID := session.UserID

auditRec := a.makeAuditRecord(r, "archiveExportTeam", audit.Fail)
defer a.audit.LogRecord(audit.LevelRead, auditRec)
auditRec.AddMeta("TeamID", teamID)

isGuest, err := a.userIsGuest(userID)
if err != nil {
a.errorResponse(w, r, err)
return
}

boards, err := a.app.GetBoardsForUserAndTeam(userID, teamID, !isGuest)
if err != nil {
a.errorResponse(w, r, err)
return
}
ids := []string{}
for _, board := range boards {
ids = append(ids, board.ID)
}

opts := model.ExportArchiveOptions{
TeamID: teamID,
BoardIDs: ids,
}

filename := fmt.Sprintf("archive-%s%s", time.Now().Format("2006-01-02"), archiveExtension)
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment; filename="+filename)
w.Header().Set("Content-Transfer-Encoding", "binary")

if err := a.app.ExportArchive(w, opts); err != nil {
a.errorResponse(w, r, err)
}

auditRec.Success()
a.errorResponse(w, r, model.NewErrNotImplemented("not permitted in plugin mode"))
}
Loading
Loading